Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . ( 7 points ) Implement a program that requests three strings from the user. Your program should concatenate the first two strings in

1.(7 points) Implement a program that requests three strings from the user. Your
program should concatenate the first two strings in the reverse order and compare
the concatenated string with the third string. If they are equal, your program
should print They are equal, otherwise, the program prints They are not
equal. A sample run is shown below:
Enter first string: you!
Enter second string: Thank
Enter third string: Thankyou!
They are equal
Enter string 1: you2!
Enter second string: Thank
Enter third string: Thankyou!
They are not equal
2.(7 points) Write a Python program that reads in 3 integers or 4 integers (user first determines 3 or 4 integers) and displays the following:
a. the average of the numbers (two decimal places suggested)
b. the maximum of the numbers
Do not use Pythons internal functions for average and maximum.
A sample run is shown below:
Enter set of 3 integers: 3
Enter first number: 7
Enter second number: 10
Enter third number: 1
The average of 7,10 and 1 is: 6.0
The maximum of the three numbers is: 10
Enter set of 3 or 4 integers: 4
Enter first number: 7
Enter second number: 10
Enter third number: 1
Enter fourth number: 6
The average of 7,10 and 1 is: 6.0
The maximum of the three numbers is: 10
3.(7 points) An integer, greater than 1, that is only divisible by 1 and itself is called
a prime number. All other numbers greater than 1 are called composite numbers.
The integers 0 and 1 are neither prime nor composite. Write a python program
that requests a positive integer from the user, determines if it is a prime,
composite or neither prime or composite and prints the message.
Sample runs are shown below:
Enter positive integer: 3
It is a prime
Enter positive integer: 4
It is a composite
Enter positive integer: 1
It is neither prime nor composite
Enter positive integer: -5
Error: You did not enter a positive integer
Enter positive integer: -2.5
Error: You did not enter a positive integer
Enter positive integer: Hi
Error: You did not enter a positive integer
4.(7 points) Implement a Python function with 3 arguments called
SimpleInterest(Principle, Interest, Years). The arguments are:
a. A principle amount (float)
b. Interest Rate (0 to 100% as a float)
c. Years (integer)
Your function should return the simple interest amount.
The formula for a simple interest is (Principle*InterestRate*Years)/100
Write your function definition in one cell and the function calling code below it or
in a different cell in Jupyter Notebook.
Your code should ensure that the user input is in the correct type and format
5.(7 points) Write a python program for a shopping cart. The program should allow
shopper to enter the product name and price. Use loop so that shopper can enter as
many inputs as necessary and validate the inputs as product name should be string
and price should be more than $0. At the end, the output should
display the total the shopper needs to pay. Use f-string to format the total
value for two decimal points and comma.
print the name and price for all the entries with appropriate headings.
6.(7 points)Rock-paper-scissors is a hand game that is played by two people. The
players count to three in unison and simultaneously "throw" one of three hand
signals that correspond to rock, paper or scissors. The winner is determined by the
rules:
Rock smashes scissors
Scissors cuts paper
Paper covers rock
Rock-paper-scissors is a surprisingly popular game that many people play
seriously (see the Wikipedia article for details).
Write a Python program to ask the users choice of Rock paper scissors. The
program then, randomly, chooses a choice for itself (the computer) and then
compares it with the users choice. The output should show, the users choice, the
programs choice and the winner.
Sample runs are shown below:
Enter your choice: rock
Computer chooses scissors
You, the user, win!
Enter your choice: paper
Computer chooses rock
I, the computer, win!
Enter your choice: scissors
Computer chooses scissors
User and computer tie!
Finally, you want to play at least 10 times. Store and display the computer
choices and user inputs in a pandas dataframe with headings.
7.(8 points) Write a program where the user and the program/computer play a
number guessing game. The program should prompt the user for a number
(between 1 and 100, inclusive) then the program/computer has to guess what the
user entered. Keep track of the number of iterations it takes for the computer to
guess the number. Sample runs are shown below:
Enter number to be guessed: 88
You entered 88, and it took the program 3 iterations to guess
Enter number to be guessed: 55
You entered 55, and it took the program 19 iterations to guess

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago