-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpythonTutorial.py
65 lines (50 loc) · 1.32 KB
/
pythonTutorial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#Hello World goes to the console
print("Hello World")
#accepts user text from the console and stores it in name
name = input("Please enter your name: ")
#says hey to name
print("Hey ", name, "! :)")
#control structures: if/elif/else block <-(for making decisions)
age = int(input("What is your age?: "))
if age >= 18:
print("You are an adult\n") #Note: \n prints a new line (like pressing enter)
elif age > 0:
print("You are a child\n")
else:
print("What???")
#i goes from 0 to 9 <- note that the range is 10 while the last
#number is 9...can you see why? (count the amount of numbers from 0 to 9)
for i in range(10):
print(i)
#makes a new line(like pressing enter)
print("\n")
#i goes from 4 to 10 <-(not including 10)
for i in range(4,10):
print(i)
#another new line
print("\n")
#i goes from 4 to 10 but is incremented by 2 each time
for i in range(4, 10, 2):
print(i)
#another newline
print("\n")
#broken while loop
''' <- Note that this is how you comment out multiple lines of code
xyz = 10
while xyz > 0:
print xyz
'''
#this while loop works
xyz = 10
while xyz > 0:
print (xyz)
xyz = xyz - 1
print("\n")
#quadratic formula: y = -b +- Sqrt[b^2 - 4ac]/(2a)
a = 1
b = -2
c = 1
y1 = -b + (b**2 - 4 * a * c)**0.5 / (2*a)
y2 = -b - (b**2 - 4 * a * c)**0.5 / (2*a)
print("y1 = ", y1, "\ny2 = ", y2)
print("\nGoodbye :)")