In: Computer Science
Question III: Programming\flowcharts\algorithms
20 |
10 |
30 |
5 |
0 |
Note: You do not need to add comments
For example: if the user entered 3 then the output will be:
3
6
9
Note: multiples of 3 are: 1 x 3= 3, 2 x 3=6, 3 x 3=9, etc.
Sorting List:
CODE:
a=[20,10,30,50]
for i in range(len(a)):
for j in range(len(a)-i-1):
if a[j]>a[j+1]:
temp=a[j] #swap adjacent elements if condition
meets
a[j]=a[j+1]
a[j+1]=temp
print(a)
Screenshots:
Python program that find hours,minutes and seconds
CODE:
#Reading input from user
t=int(input("Enter seconds::"))
#Find no.of hours
hours=int(t/3600)
t=t%3600
#Find no.of minutes
minutes=int(t/60)
t=t%60
#Find no.of seconds
seconds=t
print(str(hours)+" hour(s),"+str(minutes)+" minute(s),"+str(seconds)+" second(s)")
Screenshots:
Flow chart for first three multiples of a number