Question

In: Computer Science

Name your program file warmup.py Submit your working Python code to your CodePost.io account. In this...

Name your program file warmup.py

Submit your working Python code to your CodePost.io account.

In this challenge, establish if a given integer num is a Curzon number. If 1 plus 2 elevated to num is exactly divisible by 1 plus 2 multiplied by num, then num is a Curzon number.

Given a non-negative integer num, implement a function that returns True if num is a Curzon number, or False otherwise.

Examples

is_curzon(5) ➞ True
2 ** 5 + 1 = 33
2 * 5 + 1 = 11
33 is a multiple of 11
is_curzon(10) ➞ False
2 ** 10 + 1 = 1025
2 * 10 + 1 = 21
1025 is not a multiple of 21
is_curzon(14) ➞ True
2 ** 14 + 1 = 16385
2 * 14 + 1 = 29
16385 is a multiple of 29

Write a Python program that reads in an integer. Make sure the integer is positive (including zero). If it is then output the sum of the Curzon numbers that exist between 0 and the number. If the number is not positive then output an error message "input not valid" on a line by itself.

Repeat this process until you read in a zero, then stop.

Add the following comments to EVERY Python program for this course

# Your Name
# CSCI 236
# Date
# Program 00 - Warmup
# approximate number of hours you invested
# Grade Version (some programs will have A, B, C versions, this one does not)
# description of any major problems you ran into
# status of the program - does it compile, does it run perfectly, does it have bugs, any limitations, etc

Solutions

Expert Solution

#funnction for curzon check number

def is_curzon(num):

#make a temporary number with given first condition

cond1 = 2**number + 1

#make second temporary number

cond2 = 2*number + 1

#check for given condition

if cond1 % cond2 == 0:

return True

else:

return False


number = int(input("Enter any positive integer: "))

#Check if the number is positive

if number >= 0:

#if positive proceed to calling the isCurzon function

print(is_curzon(number))

#If not positive number, print the error message

else:

print("input not valid")

#output


Related Solutions

Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write a function that consists of a set of loops that run through an array and count the number of ones in it. Do the same thing using the where() function (use info(where) to find out how to use it) (in python)
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
PYTHON Part 2 (separate program) Ask for a file name. Don’t let the program crash if...
PYTHON Part 2 (separate program) Ask for a file name. Don’t let the program crash if you enter the name of a file that does not exist. Detecting this will also be discussed on Wednesday. If the file doesn’t exist gracefully display an error message stating the file doesn’t exist and quit the program. It the file does exist read all the values in the file. You will only need to read the file once, or more to the point,...
Write a python program that does the following: Prompt for a file name of text words....
Write a python program that does the following: Prompt for a file name of text words. Words can be on many lines with multiple words per line. Read the file and convert the words to a list. Call a function you created called list_to_once_words(), that takes a list as an argument and returns a list that contains only words that occurred once in the file. Print the results of the function with an appropriate description. Think about everything you must...
Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file....
Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18    List as Stack """ File: pyStackPostfix.py Author: JD """ # 5 7 + 6 2 -  * = 48 print("Postfix Calculator\n") stack = []              # Empty stack...
JavaScript 1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to...
JavaScript 1. FizzBuzz Submit js file with functioning code Write a program that uses console.log to print all the numbers from 1 to 120, with two exceptions. For numbers divisible by 4, print "Fizz" instead of the number, and for numbers divisible by 10 (and not 4), print "Buzz" instead. When you have that working, modify your program to print "FizzBuzz", for numbers that are divisible by both 4 and 10 (and still print "Fizz" or "Buzz" for numbers divisible...
PYTHON program that: Asks for a name, and then displays "Welcome student" plus your name on...
PYTHON program that: Asks for a name, and then displays "Welcome student" plus your name on the screen. (concatenate your name after the string) and prompts the user for 2 numbers, then calculates and displays the sum, product and average.
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
Please write in beginner level PYTHON code! Your job is to write a Python program that...
Please write in beginner level PYTHON code! Your job is to write a Python program that asks the user to make one of two choices: destruct or construct. - If the user chooses to destruct, prompt them for an alternade, and then output the 2 words from that alternade. - If the user chooses construct, prompt them for 2 words, and then output the alternade that would have produced those words. - You must enforce that the users enter real...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT