A set of code written on an IDE

1. BMI Calculator

BMI Formula
BMI & Weight Status
  • We are going to take the user’s weight (in kg s) and height (in meters).
  • Following that we are going to display the calculated BMI value (make sure to round that value to 3 decimal places) alongside with the weight status.
  • For example let’s say the user’s BMI was equal to 19.234. Then you should print this message. “ Your BMI is 19.234. You belong to Normal category .”
BMI calculator

2. Number Guessing Game

  • You can use Python’s random library (To store the secret number)
  • Player should be given a maximum of 3 chances to guess the correct number.
  • If the player’s guess is greater than the secret number then program should print “ Please try again. The secret number is less than X ”. Likewise if the player enters something less than the correct number then it should print “ Please try again. The secret number is greater than X ” (Note that ‘X’ means the number inputted by the user) If the user still has not used up all 3 of his chances then the program should ask the player for another input.
  • If the player was able to guess the number correctly within the allowed three attempts then you should print this command and terminate the program. “You have won!. The secret number was Y (Note that ‘Y’ means the secret number)
  • Unfortunately if the player was not able to guess the correct number even after the allowed 3 attempts then you should print the following and terminate the program.
Number guessing game — Code (IDE — PyCharm)

3. Rock Paper Scissors

  • You can use Python’s random library. (To store the choices of the computer)
  • Take the user input. (choice of the user)
  • Make sure to build a function to display the choices of both computer and the user.
  • Case no. 1 :- If both computer and the user has chosen the same option then program should print “ It is a tie. ”
  • Case no. 2 :- If the user has won according to the rules of the game then program should print “ You have won. ”
  • Case no. 3:- If the user has lost according to the rules of the game then program should print “ You have lost. ”
  • Case no 4:- If the user doesn’t enter a valid option then the program should print this command. “ Please enter a valid option! ”
  • Once a round is completed the program should ask the user whether he/she wants to play the game again. (take user input) If the answer is ‘yes’ repeat the same process. If not terminate the program.
Sample solution code for Rock paper and scissors

4. MCQ Quiz Game

  • We should present the user each 5 questions one by one. Before proceeding to the next question we should get the user’s answer for the question through user input.
user = input("Enter your answer here: (a/b/c) ")
  • We need to make sure that user enters [‘a’, ‘b’ or ‘c’] only. That means if the user was to input something else we should tell the user to enter only one out of the three given options.
print("Please enter a valid option")
  • Then we should store the user inputs in a list. Furthermore we should store the correct answers in a separate list.
  • Once the user has answered all 5 questions we should output his final score as a percentage.
print(f'Your final score is {str(final_score)}%')
Sample Solution code for the Quiz Game
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐