Question

ON PYTHON Exercise 1. For each of the relational/logical expressions listed in exercise1.py determine whether the...


ON PYTHON

Exercise 1. For each of the relational/logical expressions listed in exercise1.py determine whether the expression evaluates to True or False. Place a comment after each expression with the truth value and submit the updated exercise1.py file to the dropbox. For example, x = 10 y = 11 x < y # True  insert a comment after the expression

x = 10
y = 11
a = 12.5
b = -5.2

x < y
# True

x < y and a < b
x * y > 100 or a < b
not ( x + y == 21 )
not ( x < y ) or ( a > b )
x % 2 == 0 and y % 2 == 1

Exercise 2. Convert the two if-statements in the exercise2.py file into a single if-else-statement that produces the same output.

# convert the two if-stmts to one if-else-stmt

msg = input( 'Enter message: ' )

# replace these statements with a single if-else statement

if msg == 'first time':
print ( 'start up message' )
  
if msg != 'first time':
print ( 'continuing message' )

Exercise 3. Insert a conditional statement at the end of source code listed in exercise3.py that prints the error message ‘Error – value out of range’ if the user enters an integer value outside the range 0…100.

value = int( input( 'Enter the value: ') )

print( 'Value entered is', value )

# insert the additional statement(s) here

Homework Answers

Answer #1

Exercise 1:

x = 10
y = 11
a = 12.5
b = -5.2

x < y
# True
x < y and a < b
#False
x * y > 100 or a < b
#True
not ( x + y == 21 )
#False
not ( x < y ) or ( a > b )
#True
x % 2 == 0 and y % 2 == 1
#True

Exercise 2:

# convert the two if-stmts to one if-else-stmt

msg = input( 'Enter message: ' )

# replace these statements with a single if-else statement

if msg == 'first time':
print ( 'start up message' )
  
else:
print ( 'continuing message' )

Exercise 3:

value = int( input( 'Enter the value: ') )

print( 'Value entered is', value )

# insert the additional statement(s) here

if(value < 0 or value > 100):
        print('Error – value out of range')
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a...
convert to python 3 from python 2 from Tkinter import * # the blueprint for a room class Room(object): # the constructor def __init__(self,name,image): # rooms have a name, exits (e.g., south), exit locations (e.g., to the south is room n), # items (e.g., table), item descriptions (for each item), and grabbables (things that can # be taken and put into the inventory) self.name = name self.image = image self.exits = {} self.items = {} self.grabbables = [] # getters...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...