Solve the different problems by writing Python programs.
number1 and number2 to store numbers: if the
product of the two numbers is less than or equal to
1000, print their product; otherwise print their
sum.Sample inputs and outputs:
number1 = 20, number2 = 30, output
is 600number1 = 40, number2 = 30, output
is 70number1 and number2 using the
input() function. (Hint: Remember to convert the
input string to a number with the casting function
int())LIMIT, a
constant, and use it in your comparison instead of hardcoding
the number 1000.%) and print the
result (e.g., “20 is Even”, “31 is Odd”).number1.Output sample:
Enter number1: 10
Enter number2: 3
30 # 3*10 < LIMIT, we print the product
10 is Even
3 is Odd
Enter number1: 500
Enter number2: 10
510 # 500*10 > LIMIT, we print the sum
500 is Even
10 is Even
Enter number1: 0 # end the program1
2
3
4
5
6
7
8
9
100
2
4
6
8
12
14Note: Notice that 10 is skipped in the output sequence!
1
2
4
8
16
32
64
128
256-1
1
-1
1
-1
1
-1
1"Yes!"
"No!"
"Yes!"
"No!"
"Yes!"
"No!"Then, modify this loop to display the following output:
"Yes!"
"No!"
"Yess!"
"Noo!"
"Yesss!"
"Noooo!"We want to write a program that calculates and prints the details of an invoice.
True if VAT is applicable, or False if
not.VAT=20%
Invoice {} :
Subtotal : {} EUROS
Tax Amount : {} EUROS
Total (incl. taxes): {} EUROS
{ }are placeholders: fill with appropriate variables and values.
input() function to ask the user for invoice
details (invoice number, subtotal and VAT applicable). Then, print the
invoice details. Keep asking the user for next invoice details. To quit
the program, the user must leave the invoice number blank.To quit the program, leave invoice number blank (press Enter)
Enter invoice number: 71
Enter invoice subtotal: 1200
VAT applies: False
Invoice details:
VAT=20%
Invoice 71 :
Subtotal : 1200.00 EUROS
Tax Amount : 00.00 EUROS
Total (incl. taxes): 1200.00 EUROSWrite a Python program named
discount.py that calculates the final payable amount for a
purchase based on a tiered discount system.
The program must prompt the user to enter a net price (excluding tax) and compute the corresponding total price including tax (using a constant VAT rate of 20%).
It then applies a discount rate based on the calculated total price including tax:
Finally, the program must display the details using the exact format shown below.
Enter net price (excl. VAT): 2500
VAT-inclusive price 3000.00
discount 90.00
net to pay 2910.00while and print “infinite loop” at each
iteration. Terminate its execution manually using Ctrl+C
(interrupt).break
statement.Output sample:
Infinite loop (0)
Infinite loop (1)
Infinite loop (2)
Infinite loop (3)
Infinite loop (4)
Infinite loop (5)
Infinite loop (6)Write a Python program parrot.py that
continuously echoes the user’s input. The program should run
indefinitely until the user types “exit” to quit.
Sample output:
python parrot.py #run the program
hello #input
hello #output
Stop repeating what I say!
Stop repeating what I say!
exit #end the programtriangle.py that prompts the user to enter the size of a
triangle to draw (the number of lines), up to a maximum of 20
lines:*).Sample inputs and outputs:
Valid case:
Enter the triangle size: 4
*
**
***
****
*****Invalid case:
Enter the triangle size: 25
Error: The maximum allowed size is 20 lines.
half_diamond.py that prompts the user to enter the size of
the upper half of a half diamond, up to a maximum of 10 lines, and print
it.Sample inputs and outputs:
Valid case:
Enter the maximum width: 4
-
**
---
****
---
**
-Note the alternation of hyphens (
-) and asterisks (*) to draw each line
Invalid case:
Enter the maximum width: 25
Error: The size must be between 1 and 20 lines.rectangle.py
that :
Modify the rectangle.py program to
:
Sample output:
Enter the dimensions of the rectangle: 3 10
The area of the rectangle is equal to 30 units
**********
**********
**********half_diamond.py program, write a Python
program named diamond.py that prompts the user to
enter the size of the upper half of a diamond, up to a maximum of 20
lines, and print it.Enter the upper size of the diamond: 4
*
***
*****
*******
*****
***
*FizzBuzz (before being widely used by recruiters for technical interviews) is a counting game designed to help children learn division. The rules are simple: players count up to a predetermined positive integer , applying the following rules:
Write a program that outputs the sequence for the
game, where N represents the upper limit provided by the
user.
Sample output:
Welcome to FizzBuzz. How high do you want to play? 15
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
10
11
Fizz
13
14
Fizz BuzzWrite the “Guess My Number” program in Python, a classic procedural program!
The game is simple: the computer generates a random number (integer) between 1 (included) and 100 (excluded) and the player has to guess it in minimum trials.
random module to select
a secret integer between 1 (included) and 100 (excluded).input() functionTry to find the process, the different steps before coding! Use comments to help you design the process.
Hint: To help you, this a pseudo-code of the game:
1. Generate a random `secret` number
2. *Game loop*, repeat until the guess is correct:
1. Ask user for a `guess`
2. Print a message with a hint:
*"It's greater than {guess} !"* if guess < secret
*"It's lower than {guess} !"* otherwise
3. Increment the number of attempts
3. Print a congratulations message with the total number of attempts:
"Congratulations, the secret number was {secret}. It took you {attempts} attempts to guess this number."
4. End the program.Here are two data lists: one contains a series of numbers, the other a series of letters:
numbers = [1, 5, 32, 27, 12, -5, 100, -1.5, 230];
letters = ['a', 'z', 'b', 'u', 'r', 'g'];For each expressed requirement, write a function that:
d6 that simulates a
single roll of a six-sided die.Expected output:
n=10 p=..
n=100 p=..
n=1000 p=..
# etc.
Write a program that allows the user to generate
random band names. The system displays the names as a list. A band name
follows this template: The {adjective} {noun} (e.g., The
Last Biscuits, The Midnight Llamas). The program contains two list of 10
adjectives and 10 nouns (singular or plural).
Write the program with the following functions:
find_adjectives() and find_nouns():
functions that retrieve the list of adjectives and
nouns from the database.