Download presentation
Presentation is loading. Please wait.
Published byἸωσίας Βαμβακάς Modified over 5 years ago
1
Module 2 - Part 1 Variables, Assignment, and Data Types
4/9/2019 CSE 1321 Module 2
2
Python Keywords False def if raise None del import return True elif in try and else is while as except lambda with assert finally nonlocal yield break for not class from or continue global pass 4/9/2019 CSE 1321 Module 2
3
Printing strings in Python (review)
print (‘Whatever you are, be a good one.’) It’s just print! 4/9/2019 CSE 1321 Module 2 3
4
Pseudocode CLASS CountDown BEGIN METHOD Main() BEGIN s1 ← "Three... " s2 ← "Two... " s3 ← "One... " s4 ← "Zero... " PRINT(s1 + s2 + s3 + s4 + "Liftoff!") PRINTLINE() PRINT("Houston, we have a problem.") END Main END CountDown Output: Three... Two... One... Zero... Liftoff! Houston, we have a problem. Ps 4/9/2019 CSE 1321 Module 2 4
5
Python Output: def main(): s1 = 'Three... ' s2 = 'Two... '
s3 = 'One... ' s4 = 'Zero... ' print (s1 + s2 + s3 + s4 + 'Liftoff!') print () print ('Houston, we have a problem.') if __name__ == '__main__': main() Output: Three... Two... One... Zero... Liftoff! Houston, we have a problem. 4/9/2019 CSE 1321 Module 2 5
6
Escape Sequences Printing and escape sequence prints a special character in an output string. Common escape sequences: \b backspace. (e.g “B\bsecz\bret” prints what?) \t tab \n newline \r carriage return \” double quote \’ single quote \\ backslash 4/9/2019 CSE 1321 Module 2 6
7
Python # Escape sequences def main():
print ('Roses are red,\n\tViolets are blue,\n' + 'Sugar is sweet,\n\tBut I have \'commitment issues\',\n\t' + 'So I\'d rather just be friends\n\t At this point in our ' + 'relationship.') if __name__ == '__main__': main() 4/9/2019 CSE 1321 Module 2 7
8
Ps Pseudocode // Prints the number of keys on a piano. CLASS PianoKeys
BEGIN METHOD Main() BEGIN keys ← 88 PRINT("A piano has " + keys + " keys.") END Main END PianoKeys Output: A piano has 88 keys. Ps 4/9/2019 CSE 1321 Module 2 8
9
Python #prints the number of keys on a piano. def main(): keys = 88
print("A piano has ", keys, " keys."); if __name__ == '__main__': main() Output: A piano has 88 keys. 4/9/2019 CSE 1321 Module 2 9
10
Pseudocode // Print the number of sides of several geometric shapes. CLASS Geometry BEGIN METHOD Main() sides ← PRINT("A heptagon has " + sides + " sides.") sides ← 10 PRINT("A decagon has " + sides + " sides.") sides ← 12 PRINT("A dodecagon has " + sides + " sides.") END Main END Geometry Output: A heptagon has 7 sides. A decagon has 10 sides. A dodecagon has 12 sides. Ps 4/9/2019 CSE 1321 Module 2 10
11
Python def main(): sides = 7 # declare and initialize
print("A heptagon has ", sides, " sides.") sides = 10 # assignment statement print("A decagon has ", sides, " sides.") sides = 12 # assignment statement print("A dodecagon has ", sides, " sides.") if __name__ == '__main__': main() 4/9/2019 CSE 1321 Module 2 11
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.