-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintbasics.py
141 lines (128 loc) · 4.29 KB
/
printbasics.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
print "hello world"
print "Hello again"
print "i like typing this"
print "this is fun"
print "\'yay printing."
print "."*10
#
#how to use variables in printing
cars = 100 #this sets the variable cars = to 100
spaceinacar = 4.0 #this sets the variable spaceinacar to the floating point integer 4.0
drivers = 30 #this sets the variable drivers to integer
passengers = 90
carsnotdriven = cars - drivers #this subtracts the value for cars from value for drivers and sets it as a new variable carsnotdriven
carsdriven = drivers
carpoolcapacity = carsdriven * spaceinacar
averagepassengerpercar = passengers / carsdriven
print "there are ", cars, " cars available."
print "there are only ", drivers, " drivers available"
print "there will be ", carsnotdriven, "empty cars today"
print "we can transport ", carpoolcapacity, " people today"
print "we have ", passengers, "to carpool today"
print "we need to put about ", averagepassengerpercar, "in each car"
print "."*10
#
#how to embed variables inside a string
#varname = "lance"
#varage = "37"
#print "lets talk about %s." % varname
#print "lets talk about %s who is %s" % (varname, varage)
myname = 'lance zukel'
myage = 37 #the age i started learning python
myheight = 6
myweight = 180
myeyes = 'brown'
myhair = "brown"
myteethe = "white"
print "lets talk about %s" % myname
print "he is %s feet tall" % myheight
print "he's %s pounds heavy" %myweight
print "his hair is %s, and his eyes are %s" % (myhair, myeyes)
print "if i add my age %s, height %s, and weight %s i get %s" % (myage, myheight, myweight, myage + myheight + myweight)
print "."*10
"""
this lesson shows different ways of combining strings and variables
"""
x = "there are %s types of people." %10
binary = "binary"
do_not = "don't"
y = "those who know %s and those who %s." % (binary, do_not)
print x
print y
print "i said %r." % x
print "i also said '%s'." % y
hilarious = False
jokeevaluation = "ins't that joke so funny? %r"
print jokeevaluation % hilarious
w = "this is the left side of a string"
e = "this is the right side of a string"
print w + e
print "."*10
# new lesson - teaching how to add a space using a comma continuing the following print command on the same output line
end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"
# watch that comma at the end of 6. try removing it to see what happens
print end1 + end2 + end3 + end4 + end5 + end6,
print end7 + end8 + end9 + end10 + end11 + end12
print "." *10
#new Lesson
formatter = "%r %r %r %r"
print formatter % (1, 2, 3, 4)
print formatter % ("one", "two", "three", "four")
print formatter % (True, False, False, True)
print formatter % (formatter, formatter, formatter, formatter)
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
)
print "."*10
""" you should see
1 2 3 4
'one' 'two' 'three' 'four'
True False False True
'%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r'
'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said goodnight.'
You should use %s and only use %r for getting debugging information about something. The %r will give you the "raw programmer's" version of variable, also known as the "representation."
"""
# Here's some new strange stuff, remember type it exactly.
#use \n to place variable on new line
days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
print "Here are the days: ", days
print "Here are the months: ", months
print """
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5, or 6.
"""
print "."*10
"""
\\ Backslash (\)
\' Single-quote (')
\" Double-quote (")
\a ASCII bell (BEL)
\b ASCII backspace (BS)
\f ASCII formfeed (FF)
\n ASCII linefeed (LF)
\N{name} Character named name in the Unicode database (Unicode only)
\r Carriage Return (CR)
\t Horizontal Tab (TAB)
\uxxxx Character with 16-bit hex value xxxx (Unicode only)
\Uxxxxxxxx Character with 32-bit hex value xxxxxxxx (Unicode only)
\v ASCII vertical tab (VT)
\ooo Character with octal value ooo
\xhh Character with hex value hh
"""