Archive by category "python"

Guess my number python script

Modify the Guess My Number game so that the player has a
limited number of guesses. If the player fails to guess in time,
the program should display an appropriately chastising
message.

# guess my number game
# the computer generates a number between 1 and 100
# and tells the user if the number entered is smaller or higher
# than the number picked randomally by the computer

import random
print("I'm thinking of a number between 1 and 100\n")
print("Try to guess it in 5 attempts\n")

guess_total = 0
random_number = int(random.randint(1, 100))
my_number = int(input("Introduceti numarul: "))


while guess_total < = 5 : if guess_total >= 4:
        print("You've reached the max number of tries")
        break
           
    elif my_number == random_number:
        guess_total += 1
        guess_total = int(guess_total)
        print("Great. You've guessed it in", guess_total,"tries")
        break
        
    elif my_number < random_number: guess_total += 1 guess_total = int(guess_total) print("You're number is too low\n") my_number = int(input("Introduceti numarul: ")) elif my_number > random_number:
        guess_total += 1
        guess_total = int(guess_total)
        print("You're number is too high")
        my_number = int(input("Introduceti numarul: "))

# end of my wannabe program

My python journey (1)

So I’m trying to learn python using “Python for the absolute beginner, 3rd edition”
Challenges:
. Write a program that simulates a fortune cookie. The program
should display one of five unique fortunes, at random, each
time itโ€™s run.

# program to display fortune cookies
# display random one of 5 fortune cookies

import random
cookie = int(random.randint(1, 5))

if cookie == 1:
    print(cookie, "it is.", "You will win the lottery this week.")
elif cookie == 2:
    print(cookie, "it is.", "You will get laid with a hot blonde...someday.")
elif cookie == 3:
    print(cookie, "it is.", "You will get an extra hour of sleep.")
elif cookie == 4:
    print(cookie, "it is.", "You will be a successful hacker.")
elif cookie == 5:
    print(cookie, "it is.", "Nothing special will happen today. Tough luck!")
else:
    print("Error happend")

input("\nPress enter to exit!")


And here is the output of the program.

python for beginners

Me and my luck… ๐Ÿ™‚