CSE 1010 Lecture Notes - Lecture 6: While Loop, Boolean Expression

49 views3 pages
Verified Note

Document Summary

Cse 1010 - introduction to computing for engineers. The alternative of an if statement (the else statement) will also need its own if statement, and if necessary, it can also have another else statement (make sure you indent again) Example: if condition1: consequent1 else: if condition2: consequent2 else: if condition3: consequent3 else: alternate3. Instead of using else , you can just use elif . Not syntactically equal, but they are semantically equal! Example (this example below is the same as writing the example this is above): if condition1: consequent1 elif condition2: consequent2 elif condition3: consequent3 else: alternate3. Another example: choice = int(cid:383)input(cid:383)(cid:359)enter a number: (cid:359)(cid:384)(cid:384) if choice == 1: print (cid:383)(cid:359)you chose (cid:616)(cid:360)(cid:384) elif choice == 2: print (cid:383)(cid:359)you chose (cid:617)(cid:360)(cid:384) elif choice == 3: print (cid:383)(cid:359)you chose (cid:618)(cid:360)(cid:384) else: This example above is a prompt that will ask the user to input a number, such as.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents