Problem 2: Binary Game Write a program yourname_binary.py that quizzes the user on binary numbers. Your program should r

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Problem 2: Binary Game Write a program yourname_binary.py that quizzes the user on binary numbers. Your program should r

Post by answerhappygod »

Problem 2 Binary Game Write A Program Yourname Binary Py That Quizzes The User On Binary Numbers Your Program Should R 1
Problem 2 Binary Game Write A Program Yourname Binary Py That Quizzes The User On Binary Numbers Your Program Should R 1 (90.14 KiB) Viewed 9 times
Problem 2: Binary Game Write a program yourname_binary.py that quizzes the user on binary numbers. Your program should randomly generate a random sequence of 1s and Os 5 digits long (ex. 10101) and ask the user to enter the decimal equivalent of the binary number (ex. 21). The program has three functions: main(): calls generate_binary() to generate a random 5 digit binary number and asks the user to enter the decimal equivalent. Then, main() calls check_answer(binary_number, decimal_number) to check if the user entered the correct decimal number. If check_answer(binary_number, decimal number) returns True, print "Correct!". If it returns False, print "Incorrect!". After each question, ask the user "Enter 'exit' to quit. Enter anything else to play again: " and keep generating random binary numbers and getting answers from the user until they enter 'exit'. Once the user enters 'exit', print "You got N out of M questions correct. Thanks for playing!". generate binary(): is called by the main() function and generates a random 5 digit long binary number and returns it as a string. HINT: import random and use random.randint (start, stop) to select random ints between 0 and 1 check_answer(binary_number, decimal_number): is called by the main() function and takes two parameters: the randomly generated binary_number as a string and the user's decimal number answer as an int. Calculates the decimal value of the binary number, compares it to the decimal number, and returns True if they are the same and False if they are different. BINARY CARDS IMAGE
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply