Question

In python 3, how would you do the following? 1. conditional to check if choice is...

In python 3, how would you do the following?

1. conditional to check if choice is 7. if choice is 7, print out "lucky". if not, print "unlucky"

2. You're provided with a random number in a variable called num. Use a conditional to check if the number is odd. If num is odd, print "odd". If not, print "even" (use modulus % to figure out if number is odd)

Homework Answers

Answer #1

Answer 1

Code


choice = int(input("Please enter your choice: ")) # converting input as integer


if choice == 7:
print("\n\nlucky");
else:
print("\n\nunlucky");

Test Output

Answer 2

Code


num = int(input("Please enter the number: ")) # converting input as integer

if num%2 != 0:
print("\n\nodd");
else:
print("\n\neven");

Test Output

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
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in the sequence, the next number in the sequence is determined by two simple rules: If the current number n is odd, the next number in the sequence is equal to 3 * n + 1 If the current number n is even instead, the next number in the sequence is equal to one half of n (i.e., n divided by 2) We repeat this...
1. How many times the loop below will be executed? What is the value of variable...
1. How many times the loop below will be executed? What is the value of variable counter after the loop? counter = 1 while counter < 7: counter+=2 print(counter) 2. An integer is stored in a variable MyInt. Write the Python if statement to test if MyInt is even number or odd number, and print a message to show “It is even number.” or “It is an odd number”. 3. Complete the python below that asks user to enter the...
Using python language 1- Write a function for checking the speed of drivers with 3 different...
Using python language 1- Write a function for checking the speed of drivers with 3 different speeds: 55, 90, 160. If the return result is 0, it should print “Good”. If the return is not zero but less then 12, it should print: ‘Too fast“ if the return is  greater than 70, then print “Your license is suspended!” 2- Write a function that takes a series of numbers as parameters to check if the driver is speeding up or slowing down....
PYTHON 3 Write a program that prints the count of all prime numbers between A and...
PYTHON 3 Write a program that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = 21212 B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2, 5, 7, 11, 13, 17, 19, 23, and 29. Rules: You should first...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features...
Module 4 Assignment 1: Pseudocode & Python with Variable Scope Overview Module 4 Assignment 1 features the design of a calculator program using pseudocode and a Python program that uses a list and functions with variable scope to add, subtract, multiply, and divide. Open the M4Lab1ii.py program in IDLE and save it as M4Lab1ii.py with your initials instead of ii. Each lab asks you to write pseudocode that plans the program’s logic before you write the program in Python and...
This is an intro to Python question: #Write a function called linear() that takes two parameters...
This is an intro to Python question: #Write a function called linear() that takes two parameters #- a list of strings and a string. Write this function so #that it returns the first index at which the string is #found within the list if the string is found, or False if #it is not found. You do not need to worry about searching #for the search string inside the individual strings within #the list: for example, linear(["bobby", "fred"], "bob") #should...
In 1-3 sentences, describe how you would "Print all the odd numbers from 0 to x",...
In 1-3 sentences, describe how you would "Print all the odd numbers from 0 to x", Recursively using C++
Python: Write a program that prompts the user to enter a positive integer value, and compute...
Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message containing the word Error and exit the program....
Why will this not work to do a 3 rail encryption? How would I make it...
Why will this not work to do a 3 rail encryption? How would I make it work? Will it encrypt special characters? The program language Python. userString=input("What would you like to decrypt and encrypt?: ") def threeRailEncrypt(plainText): railOne="" railTwo="" railThree="" for i in range(0,len(plainText),3): railOne=railOne+plainText[i] for i in range(1,len(plainText),3): railTwo=railTwo+plainText[i] for i in range(2,len(plainText),3): railThree=railThree+plainText[i] return railThree+railTwo+railOne print() print("Encrypted version:") print(threeRailEncrypt(userString)) def threeRailDecrypt(cipherText): thirdLen=len(cipherText)//3 if len(cipherText)%3==2: x=1 else: x=0 railThree=cipherText[:thirdLen] railTwo=cipherText[thirdLen:2*thirdLen+x] railOne=cipherText[2*thirdLen+x:] plainText=""    for i in range(thirdLen): plainText+=railOne[i]+railTwo[i]+railThree[i] if...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...