2. Squares
by CodeChum Admin
Instructions:
Using a do...while() loop, continuously scan for random integers that will be inputted by the user and print out its square, separated in each line.
Once the inputted value is 0, it will still print out its square value but should then terminate the loop afterwards. Use this concept in making your loop condition.
Instructions
Using a while() loop, continuously scan for random integers that will be inputted by the user and print out its square, separated in each line.
If the inputted integer is 0, it will still print out its square value but should then terminate the loop afterwards. Use this concept as your looping condition and don't forget to declare and initialize the variable you will be using for your loop condition and make sure the initial value will not make the condition false at first.
Input
Multiple lines containing an integer.
2
6
Output
Multiple lines containing an integer.
4
36
i = 0
while True:
inp_int = int(input('Enter integer here: '))
if inp_int != i:
print(inp_int**2)
else:
print(inp_int**2)
break
Comments
Leave a comment