Assignment: Program 1 Write a program that asks the user to input an integer value less than 500 (this is variable n). T
Posted: Fri Jul 01, 2022 5:39 am
Assignment:
Program 1
Write a program that asks the user to input an integer value lessthan 500 (this is variable n). The program should then ask the userfor a second integer value (which we refer to as x). Using a WHILE loop, print all of the numbers thatdivide x into n and have no remainder. DO NOT use variables xand n in your program- make up your own variable names!!! Isuggest you use the “mod” function, which is discussed in section2.2 of “Python for everyone”.
For example, you interaction with the program might looksomething like this:
Please enter an integer that is less than 500: 20
Please enter a second number you want to divide by: 6
6
12
18
Thank you- you are now done!
Program 2a
Write a program that asks the user to input two integer valuesbetween 0 and 100 (we’ll call these numbers the upper and lowerlimits). Using a WHILE loop, print the numbers BETWEEN theupper and lower limits. Next, print the sum of all thenumbers between the upper and lower limits. Once the program hasprocessed the numbers, output the count of the numbers youprocessed, and the sum of the numbers you processed. Forthis program use a WHILE loop.
Program 2b
Write a program that asks the user to input two integer valuesbetween 0 and 100, and print the number BETWEEN the numbers that weentered AND the sum of all the numbers between the numbers the userinput. Once the program has processed the numbers, output the countof the numbers you processed, and the sum of the numbers youprocessed. For this program, however, use a FOR loopinstead of a WHILE loop.
For loops are covered in section 4.6 of “Python forEveryone”.
In addition to the book, I suggest watching BOTH of thefollowing videos:
(especially the first 5minutes)
And websites:
https://wiki.python.org/moin/ForLoop (I suggestrunning the code they show you in the first examples!!!)
https://www.w3schools.com/python/python_for_loops.asp
Program 3
For this assignment, keep in mind that ALL STRINGS areLISTS! I strongly suggest you review section4.6 of “Python for everyone” and Hasley’sPowerPoint notes about lists and for loops thatare posted on Canvas.
The assignment:
Write a program that asks the user for input. Usea FOR loop to parse the string you get from the user, fromstart to finish. For each character in the string reportout:
If the character is a letter, output the UPPERCASE and LOWERCASEversion of the letter.
IF the character is a number, output the letter and the SQUAREDvalue of the number. For example, if the character is 3, theprogram should output “The original is 3” and “The square of 3 is9”
If the character is a space, output the string “SPACE” (all uppercase).
If the character is not a letter, number, or space, output“<character> is a special character!” Where<character> is the character you are examining.
So- if I input Joe3.3 2A
The output should be
J
j
O
O
E
e
The original is 3
The square of 3 is 9
. is a special character!
The original is 3
The square of 3 is 9
SPACE
The original is 2
The square of 2 is 4
! is a special character!
Program 4
Write a program that asks the user for any number of floatingpoint numbers. When the user is done entering numbers, theyshould enter “done”. The program should then print to thescreen the count of the numbers entered, the sum of the numbersentered, and the average of the numbers entered.
Guidelines:
Submission Instructions:
TIPS
I do NOT suggest that you just start trying to hack Pythoncode. I suggest you start with a human level walk-through,then a program-level walk-through, then a flow chart, and thenpseudocode.
Once you have the flow of the program nailed down, THEN convertit to Python code.
Start early- you don’t want to wait until the night before theassignment is due to get started on this homework.
Keep it simple.
Program 1
Write a program that asks the user to input an integer value lessthan 500 (this is variable n). The program should then ask the userfor a second integer value (which we refer to as x). Using a WHILE loop, print all of the numbers thatdivide x into n and have no remainder. DO NOT use variables xand n in your program- make up your own variable names!!! Isuggest you use the “mod” function, which is discussed in section2.2 of “Python for everyone”.
For example, you interaction with the program might looksomething like this:
Please enter an integer that is less than 500: 20
Please enter a second number you want to divide by: 6
6
12
18
Thank you- you are now done!
Program 2a
Write a program that asks the user to input two integer valuesbetween 0 and 100 (we’ll call these numbers the upper and lowerlimits). Using a WHILE loop, print the numbers BETWEEN theupper and lower limits. Next, print the sum of all thenumbers between the upper and lower limits. Once the program hasprocessed the numbers, output the count of the numbers youprocessed, and the sum of the numbers you processed. Forthis program use a WHILE loop.
Program 2b
Write a program that asks the user to input two integer valuesbetween 0 and 100, and print the number BETWEEN the numbers that weentered AND the sum of all the numbers between the numbers the userinput. Once the program has processed the numbers, output the countof the numbers you processed, and the sum of the numbers youprocessed. For this program, however, use a FOR loopinstead of a WHILE loop.
For loops are covered in section 4.6 of “Python forEveryone”.
In addition to the book, I suggest watching BOTH of thefollowing videos:
(especially the first 5minutes)
And websites:
https://wiki.python.org/moin/ForLoop (I suggestrunning the code they show you in the first examples!!!)
https://www.w3schools.com/python/python_for_loops.asp
Program 3
For this assignment, keep in mind that ALL STRINGS areLISTS! I strongly suggest you review section4.6 of “Python for everyone” and Hasley’sPowerPoint notes about lists and for loops thatare posted on Canvas.
The assignment:
Write a program that asks the user for input. Usea FOR loop to parse the string you get from the user, fromstart to finish. For each character in the string reportout:
If the character is a letter, output the UPPERCASE and LOWERCASEversion of the letter.
IF the character is a number, output the letter and the SQUAREDvalue of the number. For example, if the character is 3, theprogram should output “The original is 3” and “The square of 3 is9”
If the character is a space, output the string “SPACE” (all uppercase).
If the character is not a letter, number, or space, output“<character> is a special character!” Where<character> is the character you are examining.
So- if I input Joe3.3 2A
The output should be
J
j
O
O
E
e
The original is 3
The square of 3 is 9
. is a special character!
The original is 3
The square of 3 is 9
SPACE
The original is 2
The square of 2 is 4
! is a special character!
Program 4
Write a program that asks the user for any number of floatingpoint numbers. When the user is done entering numbers, theyshould enter “done”. The program should then print to thescreen the count of the numbers entered, the sum of the numbersentered, and the average of the numbers entered.
Guidelines:
Submission Instructions:
TIPS
I do NOT suggest that you just start trying to hack Pythoncode. I suggest you start with a human level walk-through,then a program-level walk-through, then a flow chart, and thenpseudocode.
Once you have the flow of the program nailed down, THEN convertit to Python code.
Start early- you don’t want to wait until the night before theassignment is due to get started on this homework.
Keep it simple.