Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

{PYTHON} (NEED HELP) SYNTAX ERROR What to do? Your task is to write 2 functions and some program code outside the functions. One of your

{PYTHON} (NEED HELP) SYNTAX ERROR What to do?

Your task is to write 2 functions and some program code outside the functions. One of your functions is called position: and one is called awards. Your program code will ask the race administrator to input the number of racers. It then checks to make sure that the number is valid (between 1 and 20 inclusive).

Your program uses a for loop in order to make use of two nested functions: awards and position. Your program invokes the awards function and passes a function named position to it. The awards functions job is to print out a message for each racer after it obtains the finish position for the racer from the function called position. The position functions job is to prompt the judge to enter the finish position of a racer. The function then determines if the finish position is valid. To be valid, the position needs to be between 1 and n, where n is the parameter passed to the function by the program code. If the position entered is valid, the function will return its value to the awards function. If the position is not a valid number, the function will prompt the user to enter a valid number.

Once a valid position number is returned to the awards function, the awards functions job is to print Congratulations, you have won Gold if the racer came in first. It will print Congratulations, you have won Silver if the racer came in second, and Congratulations, you have won Bronze if the racer came in third. For all other entrants, it will print Thank you for participating in raising money for this worthy cause.

Show your program logic is correct by running the program several times to show that it recognizes an invalid number of racers and also correctly processes position numbers 1,2,3,4

TRY THIS CODE

num=int(input("Enter the number of racers : "))

if num >= 0 and num <= 20: for i in range(num): return Position(num) else: print("Enter valid number of racers")

def Position(num): place= int(input("Ask user for the Racer Position : "))

if place >= 0 and place <= num: return awards(place) else: print ("Enter valid number") def awards(position): if position==1: print("Congratulations, you have won gold") elif position==2: print("Congratulations, you have won Silver") elif position==3: print("Congratulations, you have won Bronze") else: print("Thank you for participating in raising money for this worthy cause")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

=+working on a micro-multinational?

Answered: 1 week ago

Question

=+j Identify the challenges of training an international workforce.

Answered: 1 week ago