Part 8.5 | Python Programming | Creating a while loop Game with sound
This is part 8.5 of a series of python coding I am having fun with and want to show others interested or stuck.
Code Example:
#Creating a while loop guessing game with sound
#I will be using code from the part 8 video
#This will loop until a condition has been met and play sound
import winsound
#Declare your starting variables with assigned values
guess = 0
ans = 7
guess = int(input("What is your guess? "))
#Creating the while loop that will continue until the correct
#answer is guessed.
while guess != ans:
winsound.PlaySound("laughing.wav", winsound.SND_FILENAME)
guess = int(input("Guess again! "))
if guess == ans:
break
else:
winsound.PlaySound("laughing.wav", winsound.SND_FILENAME)
guess = int(input("Guess again! "))
#Convert guess into a string
sGuess = str(guess)
#Print the results of the guess
winsound.PlaySound("gotcha.wav", winsound.SND_FILENAME)
print("You got it! The answer is " + sGuess)
#python #pythonprogramming #pythontutorial #pythonforbeginners #shorts
Music: Paid Subscription with Wondershare Filmora