Write a program with loops that prints the square of each number from 20 up to 220.
Output Segment
Square of 20 = 400
Square of 21 = 441
Square of 22 = 484
Square of 23 = 529
Square of 24 = 576
:
:
Square of 220 = 48400
Write a program with loops that compute the sum of all squares between 1 and 100
(inclusive).
Output
Sum of all squares from 1 to 100 (inclusive) = 338350
Write programs with loops that compute the sum of all even numbers between 2 and 100
(inclusive).
Output
Sum of all even numbers from 2 - 100 = 2550
Answers><span itemprop="name">Programming & Computer Science</span>>Python
Write a Python program that gets a number using keyboard input. (Remember to use input for Python 3 but raw_input for Python 2.)
If the number is positive, the program should call countdown. If the number is negative, the program should call countup. Choose for yourself which function to call (countdown or countup) for input of zero.
Provide the following.
At the school library, there is a need for a new library management system. One of the basic requirements of the system is to keep track of which books are in the library and which ones have been issued / checked-out by students.
Using the above management system, you are required to help the school answer the below questions:
1. Which three books have been issued the greatest number of times?
2. Which books do not have any more copies left in the library (all copies have been issued)?
3. Find out if a particular book is available in the library based on the book id.
4. Out of the entire set of books in the library, list the books that have never been checked out by students?
5. Print a list of all the books and available copies.
1. Copy the countdown function from below.
def countdown(n):
if n <= 0:
print('Blastoff!')
else:
print(n)
countdown(n-1)
Write a new recursive function countup that expects a negative argument and counts “up” from that number. Output from running the function should look something like this:
>>> countup(-3)
-3
-2
-1
Blastoff!
Write a Python program that gets a number using keyboard input. (Remember to use input for Python 3 but raw_input for Python 2.)
If the number is positive, the program should call countdown. If the number is negative, the program should call countup. Choose for yourself which function to call (countdown or countup) for input of zero.
Provide the following.
1. Copy the countdown function from below.
def countdown(n):
if n <= 0:
print('Blastoff!')
else:
print(n)
countdown(n-1)
Write a new recursive function countup that expects a negative argument and counts “up” from that number. Output from running the function should look something like this:
>>> countup(-3)
-3
-2
-1
Blastoff!
Write a Python program that gets a number using keyboard input. (Remember to use input for Python 3 but raw_input for Python 2.)
If the number is positive, the program should call countdown. If the number is negative, the program should call countup. Choose for yourself which function to call (countdown or countup) for input of zero.
Provide the following.
Given a string, write a program to print a secret message that replaces characters with numbers 'a' with 1, 'b' with 2, ..., 'z' with 26 where characters are separated by '-'.
Note: You need to replace both uppercase and lowercase characters. You can ignore replacing all characters that are not letters.
abcdefghij12345678910
klmnopqr1112131415161718
stuvwxyz1920212223242526
For example, if the given input is "python", "p" should replaced with "16", similarly"y" with "25","t" with "20","h" with "8","o" with "15","n" with "14". So the output should be "16-25-20-8-15-14".
Sample Input 1
python
Sample Output 1
16-25-20-8-15-14
Sample Input 2
Foundations
Sample Output 2
6-15-21-14-4-1-20-9-15-14-19
Sum of Prime Numbers In the Input
Given a list of integers, write a program to print the sum of all prime numbers in the list of integers.
Note: One is neither prime nor composite number.Input
The input will be a single line containing space-separated integers..Output
The output should be a single line containing the sum of all prime numbers from 1 to N.Explanation
For example, if the given list of integers are
2 4 5 6 7 3 8As 2, 3, 5 and 7 are prime numbers, your code should print the sum of these numbers. So the output should be 17.
Sample Input 1
2 4 5 6 7 3 8
Sample Output 1
17
Sample Input 2
65 87 96 31 32 86 57 69 20 42
Sample Output 2
31