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

write a Python program (with comments) to do the following: Define a list list1 = [['Rose',...
write a Python program (with comments) to do the following: Define a list list1 = [['Rose', 'Daisy'], 7, 0, 5.5, [1, 22, 2.45, 3, 6, 5.8]] and print it. Print the length of list1 (i.e. number of items in list1) with a suitable message. Print the first character of the first string in the first item of list1 with a suitable message (HINT: The first item is the item with index 0). Print the sum of the last 4 numbers...
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 that randomly assign participants for a study (use the random module)....
In Python... Write a program that randomly assign participants for a study (use the random module). The program should: Display a message stating its goal Prompt the user to enter Number of participants in the study (sample size) Minimum age of the participants Maximum age of the participants Based on these specifications, randomly assign for each participant: Gender (you can use "1" for Male and "2" for Female) Age The program should calculate and display: Total number of male participants...
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...
Write a python program to display a menu with the following options: (1) add, (2) subtract,...
Write a python program to display a menu with the following options: (1) add, (2) subtract, (3) multiply, (4) divide (5) mod, and (6) do nothing. I f the user enters something else (except 1-6), the program should display an error message. Otherwise, it should ask the user for two numbers, perform the calculation, and display the result.
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT