Note that there are some explanatory texts on larger screens.

plurals
  1. POContinually prompting user for input in Python
    primarykey
    data
    text
    <p>Objective: * Write a python program that repeatedly prompts for input of a positive number until the sum of the numbers is greater than 179. Use at least three modules/functions in your solution. * The largest number entered cannot exceed 42. * When the sum of the numbers exceeds 179, print the sum of the numbers, the largest number entered and smallest number entered. </p> <p>I just need some guidance, specifically for the "input_numbers" module. There must be an easier way to do this than to make a variable for each number. The code is not complete. I haven't even started on the two other modules yet. Thanks in advance. </p> <pre><code>def input_numbers(): while True: num1 = raw_input("Enter a positive integer no greater than 42 ") if num1 &lt;= 0: print "That is not a positive integer. Try again " elif num1 &gt; 42: print "The number cannot exceed 42. Try again " num2 = raw_input("Enter another positive integer ") if num2 &lt;= 0: print "That is not a positive integer. Try again " elif num2 &gt; 42: print "The number cannot exceed 42. Try again " num3 = raw_input("Enter another positive integer ") if num3 &lt;= 0: print "That is not a positive integer. Try again " elif num3 &gt; 42: print "The number cannot exceed 42. Try again " num4 = raw_input("Enter another positive integer ") if num4 &lt;= 0: print "That is not a positive integer. Try again " elif num4 &gt; 42: print "The number cannot exceed 42. Try again " num5 = raw_input("Enter another positive integer ") if num5 &lt;= 0: print "That is not a positive integer. Try again " elif num5 &gt; 42: print "The number cannot exceed 42. Try again " elif sum(num1, num2, num3, num4, num5) &gt; 179: print_numbers() add_numbers() def add_numbers(): print_numbers() def print_numbers(): input_numbers() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload