Question

: back to classroom run Instructions from your teacher: import random def get_message(user_num, rand_num): Eo von AwNP Comple

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import random


def get_message(user_num, rand_num):
    if user_num == rand_num:
        print("You picked the same number as the computer!")
    elif user_num < rand_num:
        print("Your number is smaller than the computer's number.")
    else:
        print("Your number is higher than the computer's number.")


def main():
    user_num = int(input("Enter a number between 1 and 5: "))
    while user_num > 5 or user_num < 1:
        user_num = int(input("Invalid number. Enter a number between 1 and 5: "))
    rand_num = random.randint(1, 5)
    print("Computer number:", rand_num)
    print("User number:", user_num)
    get_message(user_num, rand_num)


main()

Enter a number between 1 and 5: 10 Invalid number. Enter a number between 1 and 5: -4 Invalid number. Enter a number between

Add a comment
Know the answer?
Add Answer to:
: back to classroom run Instructions from your teacher: import random def get_message(user_num, rand_num): Eo von...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • import random def doTest(operation): ## complete your work here ##    # return True for now...

    import random def doTest(operation): ## complete your work here ##    # return True for now return True    responsesCorrect = 0 print("The software will process a test with 10 questions …… ") for compteur in range (10): operation = random.randint(0,1) if doTest(operation) == True: responsesCorrect += 1 print(responsesCorrect, "Correct responses")    if responsesCorrect <= 6 : print("Ask some help from your instructor.") else: print("Congratulations!") Requirement: You must use the format provided below and then complete the fill! Python! Thanks!...

  • repl,it HW 11.2 Please verify your em back to classroom run i.mport random 2 # DO...

    repl,it HW 11.2 Please verify your em back to classroom run i.mport random 2 # DO NOT DELETE you may want to collapse it. 4- def generate_number_strings (): 3 wGenerates a string that contai ns digits and spaces. 6 numbers- 7 rng range(random.randint (1, 20) 8 for i in rng: 10- if (len(numbers)> and numbers[-1:] != and i !-rng. stop and random.randint (0, 10) % 50): 11 12 13 1 14- numbers + 15 else: 16- numbers +str(random . randint...

  • I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong?...

    I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong? Thanks for any help! def even(n): if n%2==0 #Enter a Number def main(): n=int(input("Enter a number: ")) #If even print "Number is even" if(even(n)): print("The number is even") #If odd print "Number is odd" else: print("The number is odd") main() #Call the main function

  • Can you add code comments where required throughout this Python Program, Guess My Number Program, and...

    Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...

  • In Python: import math from fractions import Fraction kg = (print(int(input("Enter the avg male mass of...

    In Python: import math from fractions import Fraction kg = (print(int(input("Enter the avg male mass of your marsupial: ")))) def func1 (kg): result = (math.sqrt(math.sqrt(kg))) * math.sqrt(kg) return result def func2 (kg): result = (6.3552 * kg) + 1.8751 return result print(func1(kg)) print(func2(kg)) The def works for only when an actual number is in place, not when using the user variable input. How do I fix this?

  • Number 1) Which of the following statements imports a module into the default namespace? a. from...

    Number 1) Which of the following statements imports a module into the default namespace? a. from temperature import * b. import temperature as t c. import temperature as temp d. import temperature Number 2) Which of the following statements imports a module into the global namespace? a.from temperature import *   b. import temperature as temp c. import temperature as global d. import temperature Number 3) Code Example 4-2 def get_volume(width, height, length=2):     volume = width * height * length...

  • This is a python question. Start with this program, import json from urllib import request def...

    This is a python question. Start with this program, import json from urllib import request def main(): to_continue = 'Yes' while to_continue == 'yes' or to_continue == 'Yes': currency_code = input("Enter currency code: ").upper() dollars = int(input("Enter number of dollar you want to convert: ")) # calling the exchange_rates function data = get_exchange_rates() if currency_code in data["rates"].keys(): currency = data["rates"][currency_code] # printing the the currency value by multiplying the dollars amount. print("The value is:", str(currency * dollars)) else: print("Error: the...

  • Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from...

    Python 3 Modify the sentence-generator program of Case Study so that it inputs its vocabulary from a set of text files at startup. The filenames are nouns.txt, verbs. txt, articles.txt, and prepositions.txt. (HINT: Define a single new function, getWords. This function should expect a filename as an argument. The function should open an input file with this name, define a temporary list, read words from the file, and add them to the list. The function should then convert the list...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT