-
Notifications
You must be signed in to change notification settings - Fork 4
/
sept-05.py
112 lines (66 loc) · 2.43 KB
/
sept-05.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Intro to Python Chapter #1
# Lines that begin with # are comments -- they explain code but are not executed
# Basic Math at the repl
# You cans start repl on command line or in VS-Code - shift -comand on mac then (Python_start repl)
# 1. what is the result of: 2 + 3 * 5
# play around with different math functions at repl
2 + 3 * 5
# Nothing happens if run as a file
# run with shift-enter with curser at end of line works in interactive shell
# You need a print() function to make it show up
print(2+3*5)
# You can use a variable
n = 2 + 3 * 5
print(n)
# 2. assign 2,3 and 5 each to different variables then add/multiply them together in the print() function
# 3. same as 2 but assign the answer to a variable and print that
# 4. Change precedence to get 25, assign result to n2 and print answer (boring 15)
# 5. Add n to n2, assign it to ans and print ans - hint you should get 42
# 6. find the type for 2 -hint type(2)
type(2)
# 7. Find type for 2.5
type(2.5)
# 8. Find type for 2 + 2.5
2 + 2.5
type(2+2.5)
# Strings -- Double quotes
"Campbell"
# concatenating Strings
"Campbell" + " " + "Law" + " " + "School"
# assign string to variable
l = "law"
# 9. print() Campbell Law School
# a) All three words as a single string
# b) use concatenated strings in a print statement print("Campbell" + ...)
# c) assign to a variable and print the variable
# 10. What happens when you print() "Law" + 2019 (How can you fix it?)
# 11. What about "Campbell" * 3 ?
# Variables:
# 1) Can only be one word
# 2) Can't begin with number
# 3) Hyphens not allowed
# 4) Can't be special character like $ of '
# 5) Can't be Python keywords
#
# https://docs.python.org/2.5/ref/keywords.html
#
# and del from not while
# as elif global or with
# assert else if pass yield
# break except import print
# class exec in raise
# continue finally is return
# def for lambda try
# 12. which ones of the following are valid:
# school = "campbell Law"
# 2L = "Bob"
# law-school = "Campbell"
# total_$um = 100
# not = "no"
# 13. Write "Your First Program" page 21 in text (Hint - You can copy it)
# 14. What happens with print("I am " + 25 + " years old") - Can you fix it
# 15. Which of the following are True
# 25 == '25'
# 25 == 25.00
# 25 == 0025.00
# 25 == int("25")