Skip to main content
title and tags
Link
rolfl
  • 97.5k
  • 17
  • 218
  • 418

Making my simple program more efficient Random number guessing

edited tags
Source Link
Ethan Bierlein
  • 15.8k
  • 4
  • 59
  • 146

I just learned Python two days ago so this is probably very bad. Since i want to get better at optimization and organization, isIs there anything specifically bad here, or anything that iI could improve.? Wasted lines of code, things done in a more memory intensive way than it could be and so on. Thanks a lot for any input and I'm looking forward to learn much more, etc.

from random import*
b = 10
a = randint(1,b)
point = 1
x = 1
while x < 2:
    print("Guess a number between 1 and ", b)
    svar = int (input())
    if svar == a:
            b+=5
            point= point+point
            a = randint (1,b)
            print("You have ", point, "points!")
    elif svar < a:
            print("Higher")
    else:
            print("Lower")

I just learned Python two days ago so this is probably very bad. Since i want to get better at optimization and organization, is there anything specifically bad here or that i could improve. Wasted lines of code, things done in a more memory intensive way than it could be and so on. Thanks a lot for any input and I'm looking forward to learn much more.

from random import*
b = 10
a = randint(1,b)
point = 1
x = 1
while x < 2:
    print("Guess a number between 1 and ", b)
    svar = int (input())
    if svar == a:
            b+=5
            point= point+point
            a = randint (1,b)
            print("You have ", point, "points!")
    elif svar < a:
            print("Higher")
    else:
            print("Lower")

Is there anything specifically bad here, or anything that I could improve? Wasted lines of code, things done in a more memory intensive way than it could be, etc.

from random import*
b = 10
a = randint(1,b)
point = 1
x = 1
while x < 2:
    print("Guess a number between 1 and ", b)
    svar = int (input())
    if svar == a:
            b+=5
            point= point+point
            a = randint (1,b)
            print("You have ", point, "points!")
    elif svar < a:
            print("Higher")
    else:
            print("Lower")
Post Migrated Here from stackoverflow.com (revisions)
Source Link

Making my simple program more efficient

I just learned Python two days ago so this is probably very bad. Since i want to get better at optimization and organization, is there anything specifically bad here or that i could improve. Wasted lines of code, things done in a more memory intensive way than it could be and so on. Thanks a lot for any input and I'm looking forward to learn much more.

from random import*
b = 10
a = randint(1,b)
point = 1
x = 1
while x < 2:
    print("Guess a number between 1 and ", b)
    svar = int (input())
    if svar == a:
            b+=5
            point= point+point
            a = randint (1,b)
            print("You have ", point, "points!")
    elif svar < a:
            print("Higher")
    else:
            print("Lower")