Introduction to Programming
Today's course introduces programming concepts like using break and continue in while loops, logical operators, and variable naming conventions. Assignment 1 covers topics such as data types, variable naming best practices, and error handling when working with strings and floating numbers. Examples include the correct usage of floating point numbers, valid variable names, and formatting floating numbers. Additionally, the use of break and continue statements in loops is discussed to control program flow efficiently.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Course A201: Introduction to Programming 09/23/2010
Outlines for today Some problems in Assignment 1 Review how to use break and continue in while loop Logical Operators Finish part 1 in Assignment 3 Extension for Assignment 2
Problems in Assignment 1 Problem 1: the length of the Golden Gate Bridge and distance from Indianapolis to Bloomington should be in the type of FLOATING, not integer Problem 2: variable names such as a , c3po , aa_a1 are not very good variable names, but this doesn t make them invalid. They are still valid, although not good.
Problems in Assignment 1 Problem 2: tot.al is not valid because . cannot appear in a variable name, only letters, numbers, and underline can. Problem 2: for is not valid because it is a keyword, not because it is a built-in function
Problems in Assignment 1 Problem 3: print( The total of + num1 + and + num2 + is + total) has error because you cannot concatenate strings with integers. Problem 4-5: Please use %.2f or round() to format your outputs of floating numbers. UKPound = %.2f % (USDollar / 0.6646) after this line, UKPound is already a string. Use type() function to check the type of a variable
Usage of break while True: gpa = float(input( Enter GPA: )) if gpa > 4.0: break They are essentially the same! gpa = 0.0 while gpa <= 4.0 : gpa = float(input( Enter GPA: ))
Usage of break while True: input = input( Enter e if you want to exit the loop ) if input == e : break They are essentially the same! input = input( Enter e if you want to exit the loop ) while input != e : input = input( Enter e if you want to exit the loop )
Usage of continue counter = 0 while counter <= 10: count += counter if count == 5 continue print(counter) print( - * 20) When you reach continue, the rest of code (in the red rectangle) will be omitted, computer goes straight to next interation. Modify this block to not print out 4 and 7
Usage of continue counter = 0 while counter <= 10: count += counter if count == 4 continue if count == 7 continue print(counter) print( - * 20)
Comparison Operators Statements that will generate boolean values: 1 == 1 True 2 <= 0 False 4 > 1 True 9 != 99 True 1 == 1 False These are Comparison operators: ==, !=, <>, >, <, >=, <=
Logical Operators name = input( Enter your name: ) password = input( Enter your password: ) if name == Linger and password == 1234 : print( Hi, + name + , welcome to your safe house. ) else: print( Wrong name or password. Access denied! ) This is Logical Operator: and, or, not (3 logical operators in total)
Logical Operators Try these in shell: a = 10 b = 20 a <= 0 b <> a b > a and a >= 10 b <= a or a < b not a == b not a == 10
Logical Operators True table: a b a and b a or b not a True False False True False False True False True True True True True True False False False False False True
Lab work this week Finish Part-1 in Assignment 3 Extension for Assignment 2
Have a nice evening! See you tomorrow~