Using Python convert the following to a whileloop construct

Using Python convert the following to a while-loop construct. You need not use all the defined variables.

def main ():

     sum = 0
     number_1 = input(“Enter a number”)
     number_2 = input(“Enter a number”)
     number_3 = input(“Enter a number”)
     sum = number_1+number_2+number_3
     print(sum)
main()

Solution

Answer:

def main ():
sum = 0
i = 0
while i < 3:
sum = sum + input(\"Enter a number\")
i = i + 1
print(sum)
main();

Output:

sh-4.3$ python main.py                                                                                                                                                                                                      

Enter a number2                                                                                                                                                                                                             

Enter a number3                                                                                                                                                                                                             

Enter a number4                                                                                                                                                                                                             

9

Using Python convert the following to a while-loop construct. You need not use all the defined variables. def main (): sum = 0 number_1 = input(“Enter a number”

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site