Thursday, February 29, 2024

 Project -2 : Lets Play Rock(R) , Paper(P) and Scicessors(S) Game



So far you have learned
  • input and output,
  • if/elif/else statements,
  • basic mathematics,
  •  casting as float and int.
For this version, you have two players. Player 1 and Player 2.
You will need to create if statements (and probably nesting) to decide who has won, lost or if the game is a tie.
Make it fun and add emojis or epic comments as your players battle it out.
Keep it simple for you. Don't expect the user to type in the words rock, paper, scissors. Instead, encourage them to use R, P, or S. 

Version -1

print("Lets Play Rock(R) , Paper(P) and Scicessors(S)")
print()
player1= input ("player1 choose between R , P & S: ")
player2= input ("player2 choose between R , P & S: ")
if player1 == player2 :
print ("it is a tie")
elif player1 == "R" and player2 == "P":
print("player2 is winner")
elif player1 == "R" and player2 == "S":
print("player1 is winner")
elif player1 == "P" and player2 == "S":
print("player2 is winner")
elif player1 == "P" and player2 == "R":
print("player1 is winner")
elif player1 == "S" and player2 == "R":
print("player2 is winner")
elif player1 == "S" and player2 == "P":
print("player1 is winner")
else:
print("Entered wrong letter")

Version-2

print("E P I C 🪨 📄 ✂️ B A T T L E ")
print()
print("Select your move (R, P or S)")
print()
player1Move = input("Player 1 > ")
print()
player2Move = input("Player 2 > ")
print()
if player1Move=="R":
if player2Move=="R":
print("You both picked Rock, draw!")
elif player2Move=="S":
print("Player1 smashed Player2's Scissors into dust with their Rock!")
elif player2Move=="P":
print("Player1's Rock is smothered by Player2's Paper!")
else:
print("Invalid Move Player 2!")
elif player1Move=="P":
if player2Move=="R":
print("Player2's Rock is smothered by Player1's Paper!")
elif player2Move=="S":
print("Player1's Paper is cut into tiny pieces by Player2's Scissors!")
elif player2Move=="P":
print("Two bits of paper flap at each other. Dissapointing. Draw.")
else:
print("Invalid Move Player 2!")
elif player1Move=="S":
if player2Move=="R":
print("Player 2's Rock makes metal-dust out of Player1's Scissors")
elif player2Move=="S":
print("Ka-Shing! Scissors bounce off each other like a dodgy sword fight! Draw.")
elif player2Move=="P":
print("Player1's Scissors make confetti out of Player2's paper!")
else:
print("Invalid Move Player 2!")
else:
print("Invalid Move Player 1!")

 First simple Project - Grade Generator using python with basic understanding of coding ( if , else , print statement ,basic maths)


Giving a grade like A+ , A- , B, C, D .... as per the student obtained in an Exam out of total marks. You have to calculate the percentage and print it with the grade that the student has got.




print("Exam Grade Calculator")
subj= input ("Name of the exam:")
if subj == "cs" :
maxscore = int(input("Max possible score:"))
urscore= int(input("what is your score:"))
percentage = int((urscore/maxscore)*100)
print(percentage)
if percentage >= 90:
print("you got",percentage,"% which is a A+")
    elif percentage >= 80:
       print("you got",percentage,"% which is a A-")
    elif percentage >= 70:
       print("you got",percentage,"% which is a B")
     elif percentage >= 60:
       print("you got",percentage,"% which is a C")
    elif percentage >= 50:
       print("you got",percentage,"% which is a D")
    elif percentage >= 40:
       print("you got",percentage,"%which is a E")
    else:
       print("you got",percentage," % which is a F")
else:
       print("we dont deal with the subject")

 

A little bit of math for Python


So far we have introduced the computer to two types of numbers:
float: numbers with a decimal
int:    whole numbers

Copy this code and have a go with trying the different mathematical symbols.

adding = 4 + 3
print(adding)

subtraction = 8 - 9
print(subtraction)

multiplication = 4 * 32
print(multiplication)

division = 50 / 5
print(division)

# a number raised to the power of some number
# in this example we raise 5 to the power of 2
squared = 5**2
print(squared)

# remainder of a division
modulo = 15 % 4
print(modulo)

# whole number division
divisor = 15 // 2
print(divisor)

Lets get into coding again :

How many seconds are in a year?

tSeconds = int(input("1 min in Sec=:"))
tMinutes = int(input("1 hour in Minutes=:"))
tHours = int(input("1 Day in Hours=:" ))
#tDays = int(input("1 year in Days:"))
tYear = int(input("which year it is"))
# lets check for the leap year
if tYear % 4 == 0:
tDays = 366
Totalsecs = tDays*tHours*tMinutes*tSeconds
print("total seconds in year =",Totalsecs)
else:
tDays = 365
Totalsecs = tDays*tHours*tMinutes*tSeconds
print("total seconds in year =",Totalsecs)

  2D Dictionaries Remember that dictionaries are very similar to lists, except that they store data as key:value pairs. The value is what it...