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 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...
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...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
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...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT