In [1]:
print("Halt!")
user_input = input("Who goes there?")
print("You may pass,", user_input)
In [2]:
%%html
<iframe width="800" height="500" frameborder="0" src="http://pythontutor.com/iframe-embed.html#code=print(%22Halt!%22)%0D%0Auser_input+%3D+input(%22Who+goes+there%3F%22)%0D%0Aprint(%22You+may+pass,%22,++user_input)&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&rawInputLstJSON=%5B%22kwj%22%5D&curInstr=3&codeDivWidth=350&codeDivHeight=400"> </iframe>
In [3]:
a = 123.4
b23 = 'Spam'
first_name = "Bill"
b = 432
c = a + b
print("a + b is",c)
print("first_name is",first_name)
print("Sorted Parts, After Midnight or",b23)
In [3]:
In [3]:
In [4]:
a = 1
print(a)
a = a + 1
print(a)
a = a * 2
print(a)
In [4]:
In [5]:
number = float(input("Type in a number: "))
integer = int(input("Type in an integer: "))
text = input("Type in a string: ")
print("number =", number)
print("number is a", type(number))
print("number * 2 =", number * 2)
print("integer =", integer)
print("integer is a", type(integer))
print("integer * 2 =", integer * 2)
print("text =", text)
print("text is a", type(text))
print("text * 2 =", text * 2)
Examples
In [6]:
%%html
<iframe width="800" height="500" frameborder="0" src="http://pythontutor.com/iframe-embed.html#code=number+%3D+float(input(%22Type+in+a+number%3A+%22))%0D%0Ainteger+%3D+int(input(%22Type+in+an+integer%3A+%22))%0D%0Atext+%3D+input(%22Type+in+a+string%3A+%22)%0D%0Aprint(%22number+%3D%22,+number)%0D%0Aprint(%22number+is+a%22,+type(number))%0D%0Aprint(%22number+*+2+%3D%22,+number+*+2)%0D%0Aprint(%22integer+%3D%22,+integer)%0D%0Aprint(%22integer+is+a%22,+type(integer))%0D%0Aprint(%22integer+*+2+%3D%22,+integer+*+2)%0D%0Aprint(%22text+%3D%22,+text)%0D%0Aprint(%22text+is+a%22,+type(text))%0D%0Aprint(%22text+*+2+%3D%22,+text+*+2)&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&rawInputLstJSON=%5B%5D&curInstr=0&codeDivWidth=350&codeDivHeight=400"> </iframe>
In [6]:
In [6]:
In [7]:
# This program calculates rate and distance problems
print("Input a rate and a distance")
rate= float(input("rate: "))
distance = float(input("Distance: "))
print("Time:", (distance / rate))
In [7]:
In [8]:
%%html
<iframe width="800" height="500" frameborder="0" src="http://pythontutor.com/iframe-embed.html#code=%23+This+program+calculates+rate+and+distance+problems%0D%0Aprint(%22Input+a+rate+and+a+distance%22)%0D%0Arate%3D+float(input(%22rate%3A+%22))%0D%0Adistance+%3D+float(input(%22Distance%3A+%22))%0D%0Aprint(%22Time%3A%22,+(distance+/+rate))&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&rawInputLstJSON=%5B%2250%22,%22200%22%5D&curInstr=4&codeDivWidth=350&codeDivHeight=400"> </iframe>
In [8]:
In [9]:
# This program calculates the perimeter and area of a rectangle
print("Calculate information about a rectangle")
length = float(input("Length: "))
width = float(input("Width: "))
print("Area:", length * width)
print("Perimeter:", 2 * length + 2 * width) #둘레
In [10]:
%%html
<iframe width="800" height="500" frameborder="0" src="http://pythontutor.com/iframe-embed.html#code=%23+This+program+calculates+the+perimeter+and+area+of+a+rectangle%0D%0Aprint(%22Calculate+information+about+a+rectangle%22)%0D%0Alength+%3D+float(input(%22Length%3A+%22))%0D%0Awidth+%3D+float(input(%22Width%3A+%22))%0D%0Aprint(%22Area%3A%22,+length+*+width)%0D%0Aprint(%22Perimeter%3A%22,+2+*+length+%2B+2+*+width)&origin=opt-frontend.js&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&showOnlyOutputs=false&py=3&rawInputLstJSON=%5B%22200%22,%2230%22%5D&curInstr=5&codeDivWidth=350&codeDivHeight=400"> </iframe>
In [10]:
In [10]: