0% found this document useful (0 votes)
4 views4 pages

Codes From Revision Worksheet Python

The document contains code snippets for four simple games in Python: a dice rolling game, a color guessing game, a magic number guessing game, and a simple ATM game. Each game includes user input and conditional statements to determine the outcome based on the player's choices. The code demonstrates basic programming concepts such as random number generation, loops, and input validation.

Uploaded by

Nevan Bhagat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Codes From Revision Worksheet Python

The document contains code snippets for four simple games in Python: a dice rolling game, a color guessing game, a magic number guessing game, and a simple ATM game. Each game includes user input and conditional statements to determine the outcome based on the player's choices. The code demonstrates basic programming concepts such as random number generation, loops, and input validation.

Uploaded by

Nevan Bhagat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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")

You might also like