Python newb here. I'm looking to write an if statement that changes an integer value based upon an input and then loops the code. Unfortunately, I have two problems:
- When the brightness printers after accepting an input, the value that prints is 100 regardless of the input (-10, +10, set to 0, etc)
- The else statement prints regardless if the user enters a value that matches an if statement.
What am I doing wrong here?
# -*- coding: utf-8 -*-
var = 1
brightness = 100
while var == 1 : # This constructs an infinite loop
print 'Brightness is ', brightness
test1 = raw_input('up, down, on or off? ')
if test1 == 'up':
brightness = brightness + 10
print brightness
if test1 == 'down':
brightness = brightness - 10
print brightness
if test1 == 'on':
brightness = 100
print brightness
if test1 == 'off':
brightness = 0
print brightness
else:
print 'Try again'
print "Good bye!"
if..elif..elseinstead of so manyifelseonly applies to the lastifstatement. You have to useelifstatements in the middle if you want them all to be evaluated as a single block.