Write a function that takes an integer, val, as an argument. The function asks the user to enter a number. If the number is greater than val, the function displays Too high. and returns 1; if the number is less than val, the function displays Too low. and returns –1; if the number equals val, the function displays Got it! and returns 0. Call the function repeatedly until the user enters the right number.
What will be an ideal response?
$ cat number_guess.py
#!/usr/bin/python
def guessANumber(val):
guess = int(input('Enter your guess: '))
if guess > val:
print 'Too high.'
return 1
elif guess < val:
print 'Too low.'
return -1
else:
print 'Got it!'
return 0
while (guessANumber(6) != 0):
print 'Guess again.',
You might also like to view...
Analyze the following code:
``` public class Test { public static void main (String args[]) { int i = 0; for (i = 0; i < 10; i++); System.out.println(i + 4); } } ``` a. The program has a compile error because of the semicolon (;) on the for loop line. b. The program compiles despite the semicolon (;) on the for loop line, and displays 4. c. The program compiles despite the semicolon (;) on the for loop line, and displays 14. d. The for loop in this program is same as for (i = 0; i < 10; i++) { }; System.out.println(i + 4);
XML is a(n) ________ language
Fill in the blank(s) with the appropriate word(s).
What is the difference between a MovieClip and a Sprite?
What will be an ideal response?
Synthetic transaction monitoring is a type of passive monitoring
Indicate whether the statement is true or false.