Question
PYTHON: Here is a list of programs we wrote Grade calculator: #User friendly introduction first_name = input(Please enter your first name: ) print('Hello', first_name,
PYTHON:
- Here is a list of programs we wrote
- Grade calculator:
-
#User friendly introduction first_name = input("Please enter your first name: " ) print('Hello', first_name, 'and welcome to the digital gradebook.')
#Embed code with prompt for user entries student_grades = {} keep_going = True #Create a while loop while keep_going == True: print("Add students to the list ") name = input("Enter student's name or enter q to quit: ") if name != "q": grade = float(input("Enter the student's grade: ")) student_grades[name] = grade else: keep_going = False #Close loop and offer results print(" Student Grades: ") for name in student_grades: print("%s %.2f" % (name, student_grades[name])) #List out the grades in a summary report Grade_Summary = list(student_grades.keys()) print(" Grade Summary: %s" % student_grades)
grades = list(student_grades.values()) #Determine the highest, lowest, and average score high_grade = max(grades) low_grade = min(grades) avg_score = sum(grades)/4 print(" The highest student score is %.2f" % high_grade) print(' The lowest student score is %.2f' % low_grade) print(' The average of the scores is %.2f' % avg_score)
print(' Thanks for using the Digital Gradebook!') #END
-
- RPS game:
-
#User friendly introduction first_name = input("Please enter your first name: " ) print('Hello', first_name, 'and welcome to Rock, Paper, or Scissors.') #Explaining the game print("Winning Rules of the Rock paper scissor game as follows: " +"Rock(r) vs paper(p)->paper wins " + "Rock(r) vs scissor(s)->Rock wins " +"paper(p) vs scissor(s)->scissor wins ") import random
#Score keeping mechanism
TARGET_WINS = 4 player_wins = 0 computer_wins = 0 do_again = 'y' list_of_choices = ['r', 'p', 's'] player_sets_won = 0 computer_sets_won = 0
#The game loop while do_again == 'y': computer_wins = 0 player_wins = 0 while player_wins < TARGET_WINS and computer_wins < TARGET_WINS: player_choice = input('Please enter r, p, or s: ') computer_choice = random.choice(list_of_choices) print('Computer chooses' + ' ' +computer_choice) if player_choice == computer_choice: print('Its a draw!') elif player_choice == 'r' and computer_choice == 'p': print('Computer wins!') computer_wins += 1 elif player_choice == 'r' and computer_choice == 's': print('Player wins!') player_wins += 1 elif player_choice == 'p' and computer_choice == 's': print('Computer wins!') computer_wins += 1 elif player_choice == 'p' and computer_choice == 'r': print('Player wins!') player_wins += 1 elif player_choice == 's' and computer_choice == 'r': print('Computer wins!') computer_wins += 1 elif player_choice == 's' and computer_choice == 'p': print('Player wins!') player_wins += 1 else: print('You have entered an incorrect letter. Please enter p, r, or s.') #Conclusion of the set if player_wins > computer_wins: print('Congratulations you have won %d to %d' %(player_wins, computer_wins)) player_sets_won += 1 else: print('The computer has won %d to %d' %(computer_wins, player_wins)) computer_sets_won += 1 #Offer to play again do_again + input('Do you care to play again? y/n') do_again = do_again.strip().lower() #Display final results if player_sets_won > computer_sets_won: print('Great job! You have won %d sets to %d sets against the computer' %(player_sets_won, computer_sets_won)) elif player_sets_won < computer_sets_won: print('Tough luck. The computer has won %d sets to %d sets against you.' %(computer_sets_won, player_sets_won)) else: print('It looks like we have a tie! Both players have won %d sets.' %(player_sets_won)) #Conclude the game print('Thanks for playing!') break
-
- Pig Latin
-
#User friendly introduction first_name = input("Please enter your first name: " ) print('Hello', first_name, 'and welcome to the Pig Latin Transelator.') #Prompt the user for a sentence to translate sentence = input('Please enter a sentance statement: ') #Begin code for Pig Latin loop for word in sentence.split(' '): last_char = word[-1] if last_char in (',', '!', '?', '.'): word = word[:-1] word = word.lower() first = word[0] if first in ('a', 'e', 'i', 'o', 'u'): pig_latin = word + 'ay' else: ay_str = first + 'ay' rest = word[1:] pig_latin = rest + ay_str print(pig_latin, end = ' ')
#Conclude the loop and acknowledge the player's input print(' Thanks for using the Translator! You are on your way to becoming a Pig Latin expert!')
-
- Task
- Basically, write a program that incorporates 3 programs from the above list into one large program. So, pick 3 programs you want to incorporate
- Outline
- Display 3 programs for users to see and pick from or to quit
- Ask a user to choose which of the 3 programs he/she want to do
- Call that program as a function and let the user go through the program
- when the user is finished, return to the main program
- Example/Sample
- It doesnt have to be like this but something like this would work
- Display
Please choose from one of the following options
G Gradebook
R Rock, paper, and scissors game
P Pig Latin Processor
Q quit
- Check what users selection is
If selection is R then call program/function R.
But use a While loop
- Refer to
- the way you wrote the RPS program
- zyBooks chapter 6 for Functions
- Your program must compile without successfully
- Submit just your python code with .py extension
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started