Python 7 Levels, L3, Unit 20, While Loop Practice

Powered By EmbedPress

Exercise 1:

number = int(input("Please input how many students in the class:"))
i = 0;
sum = 0;
while i < number:
    score = int(input("Please input the score of "+str(i+1)+" student:"))
    sum = sum + score
    i = i + 1
print("The average score of the class is: ",sum/number)

Exercise 2:

year = 2017
student = 50000
while student < 200000:
    student = student+student*0.2
    year = year + 1
print("At 20% increase rate, in ",year," there will be 200,000 students.")

Exercise 3:

n = int(input("Please input a positive integer:"))
sum = 0
i = 0
while i <= n:
    sum = sum + i
    i = i + 1
print("1+..+",n,"sum is: ",sum)

Homework:

number1 = int(input("What number multiplication table would you like to check?"))
number2 = int(input("What is the max number it multiplies?"))
i = 1
while i <= number2:
    print(number1,"x",i,"=",number1*i)
i = i + 1

dahan1999

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts