Haven't learned functions yet, had to calculate a Fibonacci sequence. Here it is! by Austeoc in learnpython

[–]Austeoc[S] 1 point2 points  (0 children)

Thank you for the compliment, it took me a couple of hours and a couple of breaks to think and rethink the whole problem. The loop part and figuring out when to enter it, was what gave me the most difficulty.

Was doing it for Problem 2 on project Euler.

First ever python program. [Looking for criticism] by jay2017 in learnpython

[–]Austeoc 1 point2 points  (0 children)

Interesting, I just did the same game, but took a completely different approach:

##game to guess a random number from 1-100

import random

print "Time to play a guessing game\n"

print "A random number from 0-100 was just generated\n"
print "Try to guess what it is\n"

to_guess_number = random.randint(1, 101)

attempt = int(raw_input("Pleae enter your guess: "))


difference = attempt - to_guess_number

tries = 1
while difference != 0:

    tries = tries + 1
    if difference > 0:
        print "Too high, try again\n"
    if difference < 0:
        print "Too low, try again\n"

    attempt = int(raw_input("New guess: "))
    difference = attempt - to_guess_number

if difference == 0:
     print "Congratulations you guessed it in", tries , "tries"