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 program in Python language which will do the following: Write a program to prompt...
Write a program in Python language which will do the following: Write a program to prompt the user to enter a company name, city, state and zip code. Create a dictionary with the data. Output the dictionary. Then remove the city from the dictionary and output again.
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.
Beginning Python Programming - Sorting: Write and test a Python program to print a set of...
Beginning Python Programming - Sorting: Write and test a Python program to print a set of real numbers in descending order. The program should also print out the median of the numbers input and how many numbers were input. The program should read in numbers until a negative number is read. The negative number serves as a sentinel or marker telling the program when to stop reading numbers. The program should then sort the numbers and print them out in...
Python Write a program that loops, prompting the user for their full name, their exam result...
Python Write a program that loops, prompting the user for their full name, their exam result (an integer between 1 and 100), and then writes that data out to file called ‘customers.txt’. The program should check inputs for validity according to the following rules: First and last names must use only alphabetical characters. No spaces, hyphens or special characters. Names must be less than 20 characters long. Exam result (an integer between 1 and 100 inclusive) The file should record...
Write a python program that loops, prompting the user for their full name, their exam result...
Write a python program that loops, prompting the user for their full name, their exam result (an integer between 1 and 100), and then writes that data out to file called ‘customers.txt’. The program should check inputs for validity according to the following rules: First and last names must use only alphabetical characters. No spaces, hyphens or special characters. Names must be less than 20 characters long. Exam result (an integer between 1 and 100 inclusive) The file should record...
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 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT