Question

IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be sure to use at least 2 functions [main() and total_numbers(number, total)]. Put all inputs and outputs into the main function, with all calculations into the total_numbers function

Remember to do this in Python.

Answer #1

**Python code screen shot:**

**Sample Input:**

**Sample Output:**

**Code to copy:**

```
def main():
outFile = open("total.txt","a") #outFile is the output txt file
number = int(input("Enter a number: ")) # Ask for a number
if number != 0: # if number is 0 -> do nothing
outFile.write(str(number)+"\n") # str(number) converts it to string
total = number # initialize total to number
while(number != 0): # keep looping while number != 0, as if 0 then terminate
number = int(input("Enter a number: "))
if number != 0:
total = total_numbers(number, total) # call totak_numbers to add number to total
outFile.write(str(number)+" , "+str(total)+"\n") # write both value to outFile comma seperated
outFile.close() # close file
def total_numbers(number, total):
total = total + number # total += number
return total
main()
```

1)Write a program that asks a user for a number. If (and only
if) the number is greater than zero print “The number is valid”
2)Write a program that asks a user for a grade. If (and only if)
the grade is greater than zero and less than 101, print “The grade
is valid”
3)Write a program that asks a user how many widgets they want to
buy and prints out what the user should pay. Widgets costs 10
dollars....

Function Example: Write a Python function that receives two integer
arguments and writes out their sum and their product. Assume no
global variables.
def writer(n1, n2):
sum = n1 + n2
product = n1*n2
print("For the numbers", n1, "and", n2)
print("the sum is", sum)
print("and the product is", product)
...
1) Create a PYHW2 document that will contain your algorithms in
flowchart and pseudocode form along with your screen shots of the
running program.
2) Create the algorithm in both...

Question1: Write a Python Program that asks for the grades of
5 quizzes and then prints the highest grade. [6 Marks]
Question2: Write a Python Program that does the following
tasks. [8 Marks]
Create an
empty list
Ask the user
for 5 positive numbers and append them to the list
Find and
print the sum of all the numbers in the list
Delete the
last element from the list and then print the list
Question3:
Consider you have the following...

Write a program that asks the user for the name of a file.
The program should display only the first five lines of the
file’s contents.
If the file contains less than five lines, it should display the
file’s entire contents. by python using while
loop

Please use Python 3
4). Write a program that asks the user to enter 10 numbers. The
program should store the numbers in a list and then display the
following data:
• The lowest number in the list •
The highest number in the list
•The total of the numbers in the list
• The average of the numbers in the list
Sample input & output:
(Prompt) Enter Number 1: (User enter) 4
(Prompt) Enter Number 2: (User enter) 7...

Write a Python program that plays a number guessing game with a
human user. The human user will think of a number between 1 and
100, inclusive. Then the program has to guess what the user
entered. keep track of the number of interaction it takes for the
computer to guess the number.
sample run:
enter number to be guessed:88
output: you entered 88, and it took the program 3 iterations to
guess.

Write a python code that will ask the user to enter an integer
number n. Construct a recursive function that
prints numbers 1 to n in the form “11223344..nn”.

Write a mips assembly language program that asks the
user to enter and integer number and read it. Then ask him to enter
a bit position (between 0 and 31) and display the value of that
bit.

Write a function that takes two integer inputs and returns the
sum of all even numbers between these inputs, and another function
that takes two integer inputs and returns the sum of odd numbers
between these inputs .In main function, the program will asks the
user to enter two integer numbers and then passes them to these two
functions and display the result of each of them.
[0.5 mark] (BY
USING C PROGRAM)

This python program must have 9 functions:
•main() Controls the flow of the program (calls the other
modules)
•userInput() Asks the user to enter two numbers
•add() Accepts two numbers, returns the sum
•subtract() Accepts two numbers, returns the difference of the
first number minus the second number
•multiply() Accepts two numbers, returns the product
•divide() Accepts two numbers, returns the quotient of the first
number divided by the second number
•modulo() Accepts two numbers, returns the modulo of the...

ADVERTISEMENT

Get Answers For Free

Most questions answered within 1 hours.

ADVERTISEMENT

asked 5 minutes ago

asked 8 minutes ago

asked 10 minutes ago

asked 15 minutes ago

asked 15 minutes ago

asked 15 minutes ago

asked 15 minutes ago

asked 23 minutes ago

asked 25 minutes ago

asked 37 minutes ago

asked 44 minutes ago

asked 1 hour ago