Skip to content

Tiny-Decimals #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/Tiny-Decimals/credit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The example was solved by Mbaoma Chioma Mary (Section Leader for Section 223)
136 changes: 136 additions & 0 deletions examples/Tiny-Decimals/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<html>
<head>
Tiny-Decimals
</head>
<body>
Write a python script that displays all the decimal numbers between two whole numbers.
<br>
An example: decimal numbers between 0 and 1 <br>
<table>
<tr>
<td> 0 </td>
<td> 0.01 </td>
<td> 0.02 </td>
<td> 0.03 </td>
<td> 0.04 </td>
<td> 0.05 </td>
<td> 0.06 </td>
<td> 0.07 </td>
<td> 0.08 </td>
<td> 0.09 </td>
<td> 0.1 </td>
</tr>
<tr>
<td> 0.11 </td>
<td> 0.12 </td>
<td> 0.13 </td>
<td> 0.14 </td>
<td> 0.15 </td>
<td> 0.16 </td>
<td> 0.17 </td>
<td> 0.18 </td>
<td> 0.19 </td>
<td> 0.2 </td>
</tr>
<tr>
<td> 0.21 </td>
<td> 0.22 </td>
<td> 0.23 </td>
<td> 0.24 </td>
<td> 0.25 </td>
<td> 0.26 </td>
<td> 0.27 </td>
<td> 0.28 </td>
<td> 0.29 </td>
<td> 0.3 </td>
</tr>
<tr>
<td> 0.31 </td>
<td> 0.32 </td>
<td> 0.33 </td>
<td> 0.34 </td>
<td> 0.35 </td>
<td> 0.36 </td>
<td> 0.37 </td>
<td> 0.38 </td>
<td> 0.39 </td>
<td> 0.4 </td>
</tr>
<tr>
<td> 0.41 </td>
<td> 0.42 </td>
<td> 0.43 </td>
<td> 0.44 </td>
<td> 0.45 </td>
<td> 0.46 </td>
<td> 0.47 </td>
<td> 0.48 </td>
<td> 0.49 </td>
<td> 0.5 </td>
</tr>
<tr>
<td> 0.51 </td>
<td> 0.52 </td>
<td> 0.53 </td>
<td> 0.54 </td>
<td> 0.55 </td>
<td> 0.56 </td>
<td> 0.57 </td>
<td> 0.58 </td>
<td> 0.59 </td>
<td> 0.6 </td>
</tr>
<tr>
<td> 0.61 </td>
<td> 0.62 </td>
<td> 0.63 </td>
<td> 0.64 </td>
<td> 0.65 </td>
<td> 0.66 </td>
<td> 0.67 </td>
<td> 0.68 </td>
<td> 0.69 </td>
<td> 0.7 </td>
</tr>
<tr>
<td> 0.71 </td>
<td> 0.72 </td>
<td> 0.73 </td>
<td> 0.74 </td>
<td> 0.75 </td>
<td> 0.76 </td>
<td> 0.77 </td>
<td> 0.78 </td>
<td> 0.79 </td>
<td> 0.8 </td>
</tr>
<tr>
<td> 0.81 </td>
<td> 0.82 </td>
<td> 0.83 </td>
<td> 0.84 </td>
<td> 0.85 </td>
<td> 0.86 </td>
<td> 0.87 </td>
<td> 0.88 </td>
<td> 0.89 </td>
<td> 0.9 </td>
</tr>
<tr>
<td> 0.91 </td>
<td> 0.92 </td>
<td> 0.93 </td>
<td> 0.94 </td>
<td> 0.95 </td>
<td> 0.96 </td>
<td> 0.97 </td>
<td> 0.98 </td>
<td> 0.99 </td>
<td> 1.0 </td>
</tr>
</table>
</body>
</html>



35 changes: 35 additions & 0 deletions examples/Tiny-Decimals/soln.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#script that prints out the numbers between two whole numbers correct to 2 decimal places

def main():
program_intro()
start_num = float(input('Enter a starting whole number: '))
stop_num = float(input('Enter a stopping whole number: '))
tiny_decimals(start_num, stop_num)

def program_intro():
print('Hi, welcome! \n This program prints the tiny decimals between two whole numbers \
\n correct to 2 decimal places \n Kindly type numbers when prompted \
\n press \'ENTER\' key to prompt the next command ..')

def tiny_decimals(start_num, stop_num):
#print out the starting number
print(round(start_num,2))
#i used a while loop because i do not know how many times my code will
# run to arrive at the final answer
while start_num < stop_num:
#increase the starting number by 0.1
start_num += 0.01
#a condition that ensures numbers lesser than or equal to the stop_num
#get printed
if start_num <= stop_num:
#reassigns the start_num value to a value increased by 0.1
start_num = start_num
#a condition to ensure that a number greater than our stopping number does
#not get printed out
if start_num == stop_num:
break
print(round(start_num,2)) #print the numbers to 2 decimal places (for precision)
print(round(stop_num,2))

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions examples/Tiny-Decimals/title.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The title of this solved example is Tiny Decimals