Question

In: Computer Science

(Python) Write a program which accomplishes the following tasks: set a variable to the result of...

(Python)

Write a program which accomplishes the following tasks:

  • set a variable to the result of mathematical expression including +, -, * and / and of both Integer and Float values (or variables)
  • set a variable to the result of a combination of string values (or variables)
  • set a variable to the result of a combination of string, Integer and Float values (you may need to use the type casting functions)
  • Using the following variables:
    a = 1.3
    b = 4
    iterations = 7
    • Create a loop which will execute "iterations" times and outputs the result of the following expression:
      a = a * b
    • reset iterations to 7. create a loop which executes 'iterations' times and contains the following expression:
      iterations -= 1
    • reset iterations to a number between 6 and 12. Create a loop which executes 'iterations' times and does the following:
      • if Iterations is even:
        • subtract 0.5 from b (output a and b)
      • if iterations is odd:
        • multiply a by b (output a)
    • Demonstrate a while loop which contains both an if statement and a for loop. Explain your code.

TURN IN

  • Submit your source code
  • Execution of your program.
  • Explanation of what's happening (these could be comments in your code or a separate text submission)

Solutions

Expert Solution

result1 = 3*4+(5.6/2.3)-.4
result2 = 'a'+2*'b'
result3 = 'a'+2*'b'+int(3.5)*'c'
######################
a=1.3
b=4
iterations=7
for i in range(iterations):
a=a*b
#######################
iterations=7
while iterations>0:
iterations-=1
########################
iterations=8
a=1.3
b=4
while iterations>0:
if iterations%2==0:
b-=.5
print('a:',a,'b:',b)
else:
a*=b
print('a:',a,'b:',b)
iterations-=1


Related Solutions

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 Python program which takes a set of positive numbers from the input and returns...
Write a Python program which takes a set of positive numbers from the input and returns the sum of the prime numbers in the given set. The sequence will be ended with a negative number.
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers...
Write a program IN PYTHON of the JUPYTER NOOTBOOK that keeps getting a set of numbers from user until the user enters "done". Then shows the count, total, and average of the entered numbers. This should the answer when finished Enter a number: 55 Enter a number: 90 Enter a number: 12 Enter a number: done You entered 3 numbers, total is 157, average is 52.33333
Write a program in python that reads the elements of a set from the keyboard, stores...
Write a program in python that reads the elements of a set from the keyboard, stores them in a set, and then determines its powerset. Specifically, the program should repeatedly ask the user: Enter one more element ? [Y/N] If the user answers Y then an new element is read from the keyboard: Enter the new element in the set: This cycle continues until the user answers N to the first question. At that point the program shall compute the...
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,...
Write a program to perform the following two tasks: 1. The program will accept a string...
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 smell the rose". Display the result string. 2. Then...
Write a program to perform the following two tasks: 1. The program will accept a string...
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 smell the rose". Display the result string. 2. Then...
Write a complete and syntactically correct Python program to solve the following problem: Write a program...
Write a complete and syntactically correct Python program to solve the following problem: Write a program for your professor that allows him to keep a record of the students’ average grade in his class. The program must be written in accordance with the following specs: 1. The input must be interactive from the keyboard. You will take input for 12 students. 2. You will input the students’ name and an average grade. The student cannot enter an average below zero...
Write a python program for the following question. Complete the symptom similarity function, which measures the...
Write a python program for the following question. Complete the symptom similarity function, which measures the similarity between the symptoms of two patients. See below for an explanation of how the similarity is computed. def symptom_similarity(symptoms_A: Tuple[Set], symptoms_B: Tuple[Set]) -> int: '''Returns the similarity between symptoms_A and symptoms_B. symptoms_A and symptoms_B are tuples of a set of symptoms present and a set of symptoms absent. The similarity measure is computed by the following equations: present_present + absent_absent - present_absent -...
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain...
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain duplicated integers, and which outputs the input list as a sorted list in ascending order without duplication You can use either Ruby, C, C++, C# or Java to implement your program (referred to as P). 2. Design a test suite of 10 test cases (referred to as TC). Each test case has not more than 20 integers. 3. Test P against TC to make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT