from random import*
As others have already noted, "import random" is superior.
b = 10
a = randint(1,b)
It's important to make your names as readable as possible, single letter names are ok only in limited cases. In general, the wider the scope of the variable, the longer its name should be.
point = 1
Not sure if a typo, but it should be 'points'.
x = 1
while x < 2:
Here's how you make an infinite loop:
while True:
.
print("Guess a number between 1 and ", b)
As others said, ".format()" is better.
svar = int (input())
if svar == a:
b+=5
point= point+point
a = randint (1,b)
You should read https://www.python.org/dev/peps/pep-0008, which is pretty much the standard on how to format Python code. Here's your code, but with improved formatting:
svar = int(input())
if svar == a:
b += 5
point = point + point
a = randint(1, b)
Here's your code, modified with the above in mind:
import random
range_start = 1
range_end = 10
random_number = random.randint(range_start, range_end)
points = 1
while True:
guess = int(input("Guess a number between {} and {}\n".format(range_start, range_end)))
if guess == random_number:
range_end += 5
points *= 2
random_number = random.randint(range_start, range_end)
print("You have {} points!".format(points))
elif guess < random_number:
print("Higher")
else:
print("Lower")
Now, this is closer to what I'd write:
import random
RANGE_START = 1
def main():
range_end = 10
points = 1
while True:
random_number = get_random_number(range_end)
keep_user_guessing(range_end, random_number)
range_end += 5
points *= 2
print("You have {} points!".format(points))
def get_random_number(range_end):
return random.randint(RANGE_START, range_end)
def keep_user_guessing(range_end, random_number):
while True:
guess = get_guess_from_user(range_end)
if guess == random_number:
return
if guess < random_number:
print("Higher")
else:
print("Lower")
def get_guess_from_user(range_end):
while True:
guess = input("Guess a number between {} and {}\n"
.format(RANGE_START, range_end))
try:
return int(guess)
except ValueError:
print("You must type a number!")
# You can read up about this line online,
# it's not very important for a beginner though.
if __name__ == "__main__":
main()