Write a while loop that displays the following set of numbers: 0, 10, 20, 30, 40
ID: 3590638 • Letter: W
Question
Write a while loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000.Write an if-else statement that prints out the least of three integer variables x, y, z.
Write a for loop that will print all numbers from variable x to y multiplied by 2. (Sample variables: x=1 y=3 Sample output: 2 4 6)
Write a while loop that lets the user enter a number. The number should be multiplied by 10, assigned to a variable named product and printed to the screen. The loop should iterate as long as product is less than 10.
***These are for Python Coding. Write a while loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000.
Write an if-else statement that prints out the least of three integer variables x, y, z.
Write a for loop that will print all numbers from variable x to y multiplied by 2. (Sample variables: x=1 y=3 Sample output: 2 4 6)
Write a while loop that lets the user enter a number. The number should be multiplied by 10, assigned to a variable named product and printed to the screen. The loop should iterate as long as product is less than 10.
***These are for Python Coding. Write a while loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 . . . 1000.
Write an if-else statement that prints out the least of three integer variables x, y, z.
Write a for loop that will print all numbers from variable x to y multiplied by 2. (Sample variables: x=1 y=3 Sample output: 2 4 6)
Write a while loop that lets the user enter a number. The number should be multiplied by 10, assigned to a variable named product and printed to the screen. The loop should iterate as long as product is less than 10.
***These are for Python Coding.
Explanation / Answer
NOTE: I have completed programs for your assignment. Please check and let me know if you have any questions. I will acknowledge back with a response within 24 hours. Thanks for your patience.
I have coded programs for your questions but if you just want only the if or while or for loop for each of the prog but not the entire program you can just pick the bolded one in each of the programs.
Code for prog-1:
Unix Terminal> cat prog1.py
#!/usr/local/bin/python3
def main():
# initializing variable to zero
i = 0
# iterating through numbers from 0 to 1000
while i <= 1000:
# printing the value of i
print(i)
# increment the variable i to 10 each time
i += 10
if __name__=='__main__':
main()
Unix Terminal>
Code output:
Unix Terminal> python3 prog1.py
0
10
20
30
40
50
60
70
80
90
100
......
NOTE: The above prog1.py output is still there but truncated to fit the screen as the output span across multiple screens
Code for prog-2:
Unix Terminal> cat prog2.py
#!/usr/local/bin/python3
def main():
# taking x, y, z values input from the user
x = int(input('Enter the value for x: '))
y = int(input('Enter the value for y: '))
z = int(input('Enter the value for z: '))
# checking if x is the least number
if x < y and x < z:
print('Least number is', x)
# checking if y is the least number
elif y < x and y < z:
print('Least number is', y)
# flow will come here only if z is the least number
else:
print('Least number is', z)
if __name__=='__main__':
main()
Unix Terminal>
code output:
Unix Terminal> python3 prog2.py
Enter the value for x: 10
Enter the value for y: 9
Enter the value for z: 2
Least number is 2
Unix Terminal>
Unix Terminal> python3 prog2.py
Enter the value for x: -1
Enter the value for y: -2
Enter the value for z: 90
Least number is -2
Unix Terminal>
Code for prog-3:
Unix Terminal> cat prog3.py
#!/usr/local/bin/python3
def main():
# taking x and y values from the user
x = int(input('Enter the value for x: '))
y = int(input('Enter the value for y: '))
# printing each value from x to y multiplied by 2
for i in range(x, y+1):
print(i * 2, end=' ')
print()
if __name__=='__main__':
main()
Unix Terminal>
Code output:
Unix Terminal> python3 prog3.py
Enter the value for x: 1
Enter the value for y: 3
2 4 6
Unix Terminal>
Unix Terminal> python3 prog3.py
Enter the value for x: 2
Enter the value for y: 10
4 6 8 10 12 14 16 18 20
Unix Terminal>
Code for prog-4:
Unix Terminal> cat prog4.py
#!/usr/local/bin/python3
def main():
# initial value of x to enter into while loop
prod = 100
# iterating through while loop until product is less than 10
while prod > 10:
# taking a number from the user as input
x = float(input('Enter a number: '))
# multiplying given number by 10
prod = x * 10
# displaying product of the number
print('Product of the number', x, ' is:', prod)
if __name__=='__main__':
main()
Unix Terminal>
Code output:
Unix Terminal> python3 prog4.py
Enter a number: 10
Product of the number 10.0 is: 100.0
Enter a number: 90
Product of the number 90.0 is: 900.0
Enter a number: 100
Product of the number 100.0 is: 1000.0
Enter a number: 8.9
Product of the number 8.9 is: 89.0
Enter a number: 0.3
Product of the number 0.3 is: 3.0
Unix Terminal>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.