Going From Psuedocode to Python Code
CS 1111 – September 4, 2019
to Python Code CS 1111 September 4, 2019 Logistics You do not need - - PowerPoint PPT Presentation
Going From Psuedocode to Python Code CS 1111 September 4, 2019 Logistics You do not need to do Lab02 Counting, nor can you get credit for it The labs are intended primarily for 1110 We will do roughly every other lab Our first
CS 1111 – September 4, 2019
describe an algorithm
language
sales tax.
calculate the final total.
Psuedocode Flow Chart
Get item price Subtract 20% discount Add 5% sales tax Display final sale price Start End
is executable with that input
external perspective (buying -3 gallons of gas, or saying your birthday is 13/45/3000)
Psuedocode Flow Chart
1. Repeat step 1
Get item price Subtract 20% discount Add 5% sales tax Display final sale price Start End
false
item price < 0
true
Psuedocode
1. Get price from the user
code (.py file)
into byte code (.pyc file)
z = 0 x = 3 y = x while x != 0: z = z + y x = x – 1 y = z ADD R3 R2 R3 SUB R0 R0 R1 BZERO 4 BRANCH 0 MOVE R2 R3 HALT
High-Level Language Assembly Language Machine Language
Compiler/ Interprette r Assembler
10100001001011 01010001111011 01110000110101 00100110101010 01110010101101 10111101011111 11111111111
we use comments
have no #, the entire program won’t compile!)
1. Select all lines of code to be commented 2. If you have windows
1. Hit CTRL + /
3. If you have Mac
1. Hit Command + /
loop
# 1. Implicit continuation: divide statements after parentheses, brackets, and braces # and before or after a plus operator print("My name is Will" + " and my favorite courses are " + "\nCS 1111" + "\nCS 2110" + " and \nCS 2501 SDE") # 2. Explicit continuation: use the \ character to divide statements anywhere on a line t = "My name is Will" + " and my favorite courses are " \ + "\nCS 1111" \ + "\nCS 4640" \ + " and \nCS 2501 SDE" print(t)
print quotation marks?”
print("My favorite courses are : " + "'CS 1111'") # use different quatations print("My favorite courses are : " + "\'CS 1111\'") # use an escape character print("My favorite courses are : " + "\"CS 1111\"") # use an escape character
x = 5 # 5 is a literal y = 3 # 3 is a literal
x = 7 # x can be changed to another literal x = y # variable can also be changed to other variables x = x + 1 # variable can also be set to the value of an expression
quantity1 = 10 # set quantity1 to an int value of 10 quantity1 = 5.0 # set quantity1 to an int value of 5.0 quantity1 = "15" # set list_price to a str value of "15", not an int of 15
r = 5 # Create variable r y = R # Error because R is not a variable, but r is y = r # Valid