hello there, well im back;) with a few more questions that i would like clarification with. I have completed up to data structures in python and my next topic is 'object oriented programming':| . Just wanted to clear up some things first:)
guess=int (input ('enter a number:'))
Q1. in this line there is no 'print' function yet 'enter a number' is printed onto the screen and why is there an 'int' preceding that line? is that necessary to specify what type of input is taken from the user?
age=17 run=True while run: guess=int (input('enter an age:')) if guess==age: print ('congrats you got it') break elif guess<age: print ('thats too low..') else: print ('thats too high') print ('while loop is now over..')
Q2. I understand what happens in the above, but..what exactly does 'while run:' tell the computer?, what is 'true' exactly?, in order for that loop to run..? (sorry if im vague i think i confused my self here...).
s=input ('enter something:')
break #breaks program completely, and quits from console
print ('strig length is too small')
print ('the entered input is long enough')
Q3. here, why is continue used?, cant we just say else: print('the entered input is long enough')?. How does a continue statement come in handy?
#"local variables"/functions3 x=50 def func(x): print ('x is',x) x=2 print ('changed local x to', x) func(x) print ('x is still', x)
Q4. What is considered local in this case?, Isn't a variable inside a function considered to be local? because if the 'x=2' was not there it will print '50' nonetheless...??
x=50 def func(): global x print ('x is:',x) x=2 print ('changed global x to:',x) func() print ('value of x is:',x)
Q5. This seems to be the same as the previous but it calls for x right??, yet in the previous example to print out the value of x 'global' is not needed. How does that work?