Question

In: Computer Science

Write a Python program (with comments) to do the following: Assign the value '2+1' to a...

  1. Write a Python program (with comments) to do the following:
    1. Assign the value '2+1' to a variable str1.
    2. Use the eval() function to evaluate str1and assign the result to a variable num1.
    3. Ask the user to input their birth month and assign it to a variable month and then print it with a suitable message.
    4. Determine the number of letters in month and display the result with a suitable message.
    5. Determine how many times the letter 'r ' occurs in month and display the result with a suitable messag
    6. Concatenate the string month num1 times and print it with a suitable message.
    7. Print the last 2 characters of month in uppercase, with a suitable message.

Solutions

Expert Solution

#*******************main.py*************************#

str1 = '2+1' #assign variable
num1 = eval(str1)#evaluate funtion
month = input("Enter birth month: ")#prompt for month
print("Birth month is: ",month)#print month
print("Number of letter in Birth month: ",len(month))#length of moth
print("Letter r in the month: ",month.count('r'))#occurrence of r
conctString = "";
while(num1!=0):
conctString = conctString+month;
num1= num1-1;
print("Concatinating String ",conctString)#print conctString
print("Last two letter in Upper case: ",month[(len(month)-2):(len(month))].upper())#last two upper

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are...
What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are at least 40 lines of comments and 40 lines of code (1 point) b) the problem is described at the top of the program in a readable fashion (1 point) c) the code includes at least one instance of each of the five learning objectives listed above. (3 points) d) the code solves the problem. This may be assessed in part by a 'code...
What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are...
What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are at least 40 lines of comments and 40 lines of code (1 point) b) the problem is described at the top of the program in a readable fashion (1 point) c) the code includes at least one instance of each of the five learning objectives listed above. (3 points) d) the code solves the problem. This may be assessed in part by a 'code...
IN PYTHON Write a program to do the following: Solve the a set of equations as...
IN PYTHON Write a program to do the following: Solve the a set of equations as mentioned in "Zybook 5.20 LAB: Brute force equation solver". Instead of the arithmetic operators use your own function defined in a module named calc. You must provide two files (calc.py, brute_force_solver.py) :- 1) calc.py:- Add function named 'add' instead of using operator '+' [10pts] Add function named 'difference' instead of using operator '-' [10pts] Add function named 'product' instead of using operator '*' [10pts]...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
1. Write a Python program that performs the following: 2. Defines an array of integers from...
1. Write a Python program that performs the following: 2. Defines an array of integers from 1 to 10. The numbers should be filled automatically without the need for user inputs 3. Find the sum of the numbers that are divisible by 3 (i.e., when a number is divided by 3, the remainder is zero) 4. Swap the positions of the maximum and minimum elements in the array. First, you need to find the maximum element as shown in the...
Please include comments on what you are doing.   Using linked lists, write a Python program that...
Please include comments on what you are doing.   Using linked lists, write a Python program that performs the following tasks: store the records for each college found in the input file - colleges.csv - into a linked list. (File includes name and state data fields) allow the user to search the linked list for a college’s name; display a message indicating whether or not the college’s name was in the database allow the user to enter a state's name and...
By only importing multiprocessing Write a python program which do the following : 1- Create one...
By only importing multiprocessing Write a python program which do the following : 1- Create one process this process must-read the content of a file “read any file content exist in your machine” and after that create another process in the first process function which will get the file content as a parameter for the second process function. 2- The second process function will get the file content and check out if there are any special characters or numbers in...
write a python program to do the following: ask a student for 3 coefficients a b...
write a python program to do the following: ask a student for 3 coefficients a b c using the high_school_quizz to display the solutions of a quadratic problem. after, ask the student if he would like another quadratic equation solved If the student answers anything but yes, the program terminates by displaying a good bye message if the student answers yes (any form of yes should be acceptable) , the student is asked for the coefficient again and the resulting...
Who knows to do this topic with python code? Write a program to perform the following...
Who knows to do this topic with python code? Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT