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: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
In Python write a program that prompts the user for a file name, make sure the...
In Python write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try...
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 Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
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,...
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...
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...
Python 3 Fix the code so the program reads the file and see if the bar...
Python 3 Fix the code so the program reads the file and see if the bar code was already inputted 3 times if so, it ishows a warning indicating that the item was already tested 3 times Code: import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook from tkinter import messagebox from datetime import datetime window = tk.Tk() window.title("daily logs") window.grid_columnconfigure(1,weight=1) window.grid_rowconfigure(1,weight=1) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT