Codes from revision worksheet Python
Dice rolling game :
import random
computer_number = [Link](1,6)
user_number = int(input("Enter A Number from 1 to 6"))
if user_number == computer_number:
print("It's a Tie!")
elif user_number > computer_number:
print("You Win!")
else:
print("You Lose!")
Output:
Color Guessing game🎨:
colour="Red"
user_colour = input("Enter any colour of your choice")
if user_colour == colour:
print("You have guessed the colour!")
elif user_colour != colour:
print("Your guess is wrong!")
else:
print("Invalid Input")
Magic Number guessing game :
import random
def number_guessing_game():
target = [Link](1,100)
attempts = 0
print("Welcome to the number guessing game!")
print("I'm thinking of a number between 1 and 100.")
while True:
try:
guess = int(input("Enter your guess:"))
attempts += 1
if guess < target:
print("Too low! Try again.")
elif guess > target:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed
(target) correctly!")
print(f"It took you (attempts)
attempts.")
break
Simple ATM Game :
balance=5000
print("ATM Menu")
print("1. Check Balance")
print("2. Withdraw Money")
choice = int(input("Enter your choice:"))
if choice == 1:
print("your current balance is:",balance)
elif choice == 2:
amount = int(input("Enter amount to withdraw:"))
if amount <= balance:
Withdraw= balance - amount
print("Withdrawal succesful.")
print("Remaining balance:", Withdraw)
else:
print("Insufficient balance")
else:
print("Invalid choice")