Posts

Snake, Water Or Gun Game Using Python

 Snake, Water Or Gun Game Using Python : import random def gameWin ( comp , you ):     if comp == you:         return None     elif comp == 's' :         if you == 'w' :             return False         elif you == 'g' :             return True     elif comp == 'w' :         if you == 'g' :             return False         elif you == 's' :             return True     elif comp == 'g' :         if you == 's' :             return False         elif you == 'w' :             return True print ( "Computer's Turn: Snake(s), Water(w), or Gun(g)?" ) randNo = random.randint( 1 , 3 ) if randNo == 1 :     comp = 's' elif randNo == 2 :     comp = 'w' elif randNo == 3 :     comp = 'g' you = input ( "Your Turn: Snake(s), Water(w), or Gun(g)?" ) print ( f "Computer chose { comp } " ) print ( f "You chose { you } " ) result = gameWin(comp, y

Number Guessing Game Using Python 3

Number Guessing Game Using Python 3: import random num_rounds = 5 max_guesses = 10 score = 0 print ( "Welcome to the Number Guessing Game!" ) print ( "You will play" , num_rounds, "rounds. Each round, you have to guess a number between 1 and 100." ) print ( "You will score points based on the number of attempts taken to guess the number." ) print ( "Let's get started! \n " ) for i in range (num_rounds):     secret_number = random.randint( 1 , 100 )     num_guesses = 0     print ( "Round" , i+ 1 , "starts now!" )     # print("Your Guessing Number is:",secret_number)     while num_guesses < max_guesses:         guess = int ( input ( "Guess a number between 1 and 100: " ))         num_guesses += 1         if guess == secret_number:             print ( "Congratulations! You guessed the secret number in" , num_guesses, "guesses!" )             round_score = max_guesses

Write A Python Program To Find Max Between Three Numbers.

 Write A Python Program To Find Max Between Three Numbers Enter By The User. Code: num1 = int ( input ( "Enter The First Number:" )) num2 = int ( input ( "Enter The Second Number:" )) num3 = int ( input ( "Enter The Third Number:" )) if num1 > num2 and num1 > num3 :     print ( f " { num1 } is Greatest Number" ) elif num2 > num1 and num2 > num3 :     print ( f " { num2 } is Greatest Number" ) else :     print ( f " { num3 } is Greatest Number" ) Output: Enter The First Number:47 Enter The Second Number:50 Enter The Third Number:48 50 is Greatest Number Download Code

Make A Calculator Using If else Statement in Python

 Make A Calculator Using If else Statement in Python Code - num1 = int ( input ( "Enter The First Number: " )) operator = input ( "Choose Operater +,-,*,/,%:" ) num2 = int ( input ( "Enter The Second Number: " )) if operator == "+" :     print ( "Output = " ,num1 + num2) elif operator == "-" :     print ( "Output = " ,num1 - num2) elif operator == "*" :     print ( "Output = " ,num1 * num2) elif operator == "/" :     print ( "Output = " ,num1 / num2) elif operator == "%" :     print ( "Output = " ,num1 % num2) else :     print ( "Invalid Input!" ) Output -  Enter The First Number: 47 Choose Operater +,-,*,/,%:+ Enter The Second Number: 3 Output =  50 Download Code

Write Multiplication Table Using While Loop In Python

 Write Multiplication Table Using While Loop In Python Code: Num = int ( input ( "Enter The Number :" )) i = 0 while i < 10 :     i = i + 1     print ( f " { Num } X { i } = { Num * i } " )     # or     # print(Num,"X",i,"=",Num*i)     # or     # print(str(Num) + "X" + str(i) + "=" + str(Num*i)) Output: Enter The Number:8 8X1=8 8X2=16 8X3=24 8X4=32 8X5=40 8X6=48 8X7=56 8X8=64 8X9=72 8X10=80 Download Code

Write Multiplication Table Using For Loop In Python

Write  Multiplication Table Using For Loop In Python Code: Num = int ( input ( "Enter The Number :" )) for i in range ( 1 , 11 ) :     print ( f " { Num } X { i } = { Num * i } " )     # or     # print(Num,"X",i,"=",Num*i)     # or     # print(str(Num) + "X" + str(i) + "=" + str(Num*i)) Output: Enter The Number:4 4X1=4 4X2=8 4X3=12 4X4=16 4X5=20 4X6=24 4X7=28 4X8=32 4X9=36 4X10=40 Download Code

Write a program to find out whether a given post is talking about "harry" or not using Python?

write a program to find out whether a given post is talking about harry or not? Code: post = input ( "Enter a post: " ) if 'harry' in post . lower ():     print ( "Yes! the post contains the name Harry." ) else :     print ( "No! the post does not contain the name Harry" ) Output: Enter a post: harry Yes! the post contains the name Harry. Enter a post: HARRY Yes! the post contains the name Harry. Enter a post: Harry Yes! the post contains the name Harry. Download Code