Python Answers

Questions answered by Experts: 5 288

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

a) Write a program that reads a string as input from the user. Implement defensive programming so that the string is not empty.
b) Then, print the string after removing the character in position N (1 up to the length of the string) that will be indicated by the user. Implement defensive programming so that the position indicated by the user is valid.
c) Finally, ask the user for a character and return the number and percentage of appearances of that character in the original string.
We assume that one machine offers four different types of drinks (coffee, coffee with milk, chocolate and chocolate with milk), which cost € 1.50, € 1.80, € 2.10 and € 2.40 respectively. The machine accepts 10, 20 and 50 cent coins, one (1) euro and two (2) euro coins, as well as € 5 and € 10 banknotes, and returns change using only coins. To implement a program, which:
a) To display a selection list (menu) of the offered items (numbered from 1 to 4) with the corresponding price for each, the option 0 to exit the program and then reads the user's choice (preferred item or exit), applying defensive programming to ensure that the user enters a value between 0 and 4.





Create a Python program to rename the Excel spreadsheets (found in the folder attached to this assignment) to add SCC in front of each file name. Save the newly named files in a new directory. 

I can put the link in there for it


4. What's in There?

by CodeChum Admin



Instructions:

  1. Create a variable that accepts a positive integer.
  2. Create an empty list. Then, using loops, add string values to your list using the input() function. The number of string values to be added are dependent on the inputted value on the first inputted integer.
  3. Create another variable that accepts a non-negative integer. The number must only range from 0 until the value of the first inputted integer.
  4. Using your understanding on accessing list elements, access and print out the list element having the index position of the second inputted integer.



Input

The first line contains an integer n which is the size of the array.

The next n lines contains a string on each.

The last line contains an integer which is the index to be accessed and printed.

6
Learning
Programming
made
easy
with
Cody!
5



Output

A line containing a string.

Cody!

1. String Replacement

by CodeChum Admin



Instructions:

  1. Create two variables that will accept string values.
  2. A list containing three string values is already given to you in the code editor on the side. First, insert the first inputted string to the end of the list.
  3. Then, insert the second inputted string into the beginning of the list.
  4. There are now 5 elements on the given list. Now, remove the 4th element of the list. Apply the concept of index positions in order to access the 4th string element and successfully remove it from the list.
  5. Print out the remaining contents on the list, each separated by a new line, using loops.


Input

Two lines containing a string.

fun
Python


Output

A line containing a string.

Python is really fun

2. Cubes and Squares

by CodeChum Admin


Instructions:

  1. An array containing 40 integer elements is already provided for you in the code editor below.
  2. Using loops and conditions, print out the cube of the array element if it is a positive number, and print out the square of the number if it is negative. Each result must be printed out separately by each line.



Output

The squares and cubes of the elements in the array.

4
1
1
8
27
.
.
.

Zeller’s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is


where: h=(q+²⁶(m+I)/10 + k/4 + i/4 + 5i)%7



• h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday).


• q is the day of the month


• m is the month (3: March, 4: April, …, 12: December). January and February are counted as months 13 and 14 of the previous year.


• j is the century (i.e., Year/100).


• k is the year of the century (i.e., year%100)



Note that the division in the formula performs an integer division. Write a program that prompts the user to enter a year, month, and day of the month, and displays the name of the day of the


week. Here are some sample runs:



(Hint: January and February are counted as 13 and 14 in the formula, so you need to convert the user input 1 to 13 and 2 to 14 for the month and change the year to the previous year.)

Create a program that will accept number of students and number of quizzes of students. Based on this input the program will accept the name of the student and the quiz grades of the student. The input will be stored to a dictionary. The name of the student will be the key and the quizzes will be the value in list format (e.g., {“Jose S. Uy”: [87,90,97,80,95], “Rowena M. Evangelista”: [88,87,90,97,83].


The program will output the list of quizzes per student, the lowest quiz, the highest quiz, and the average quiz grade.




Write a program to calculate the average of

all scores entered between 0 and 100. Use a

sentinel-controlled loop variable to terminate the

loop. After values are entered and the average

calculated, test the average to determine whether

an A, B, C, D, or F should be recorded.




lat = [40.59, 40.52, 40.621, 40.519, 40.56, 41.265, 40.61, 40.806, 41.259, 41.265, 41.264, 41.264, 41.259, 41.262, 41.263]
lon = [69.532, 69.419, 69.354, 69.263, 69.478, 70.805, 69.706, 70.331, 70.815, 70.823, 70.815, 70.81, 70.824, 70.811, 70.811]

The lat list indicates how far north and south Gracie the seal has traveled, and the long list represents how far east and west she has traveled. The larger the latitude value, the further north the seal was located, and for this area of the world, the larger the longitude value, the further west the seal is located.

Write a program to calculate the farthest in each direction that Gracie was located throughout her travels. Add four print statements to the lines of code above that output the following, where the number signs are replaced with the correct values from the correct list:

Farthest north = #
Farthest west = #
Farthest south = #
Farthest east = #








LATEST TUTORIALS
APPROVED BY CLIENTS