Question

In: Computer Science

IN PYTHON create a python program that accepts input from the user in the following sequence:...

IN PYTHON

create a python program that accepts input from the user in the following sequence:

1. Planet Name

2. Planet Gravitational Force(g)

for data, use the planets of our solar system. The data input is to be written in 2 separate lists, the names of which are:

1. planetName

2. planet GravitationalForce(g)

A third list is required that will store the weight of a person with mass of 100kg, the formula of which is: W=mg(where m is mass of 100kg, and g is gravitational force of the planet)

Name this list:

3. weightOnPlanet

your are required to use loops in inputting the required data. Data inputting is to continue until the sentinel value of QUIT is entered for he planet name.

print out the results on screen in readable format

i.e. (Planet Name: Earth, Gravitational Force: xxxx, Weight: xxxx

Pluto is not considered by many not to be a planet of our solar system anymore.

Modify the same program to remove Pluto from all 3 lists in the program. Reprint the lists again, in the same format as the previous print.

A hypothetical object called Planet Nice is could exist in the outermost regions of our solar system. It is conjectured it maybe about 10 times the mass of planet Earth and let's suppose the 5 times the gravitational for of earth.

Modify your program to insert this hypothetical object in the 3rd position of your lists, including the computation of weight of a 100kg person.

REPRINT THE LISTS AGAIN IN THE SAME FORMAT AS THE PREVIOUS 2 PRINTS

Solutions

Expert Solution

Solution:

The program is implemented as shown below. The sentinel is set for Quit.

When the user enters 0 in the planetName the inputting stops.

Code:

Quit=1 #setting sentinel for Quit
planetName=[]
planetGravitationalForce=[]
weightOnPlanet=[]
while(Quit!=0):
planetName.append(input("Enter planet name and enter 0 if you want to stop inputting")) #Read input of planet name
if(planetName[-1]=='0'):
Quit=0 #If quit is requested, set sentinel and quit
continue
planetGravitationalForce.append(float(input("Enter gravitational force"))) #Read input of gravity

for i in planetGravitationalForce:
weightOnPlanet.append(100*i) #compute weight using w=mg and append it.
planetName.remove('0')

for i in range(len(planetName)): #print the data
print("Planet Name=", planetName[i])
print("Gravitational Force=", planetGravitationalForce[i])
print("Weight=", weightOnPlanet[i])

#removing Pluto
print("After removing Pluto")
index=planetName.index("Pluto")
planetName.pop(index) #Removing the pluto from plane name list
planetGravitationalForce.pop(index) #Removing pluto gravity from list
weightOnPlanet.pop(index) #Removing pluto weight from its list
for i in range(len(planetName)):
print("Planet Name=", planetName[i]) #Print the data after removing pluto
print("Gravitational Force=", planetGravitationalForce[i])
print("Weight=", weightOnPlanet[i])


#Inserting Nice   
print("After inserting Nice")
planetName.insert(2,"Nice") #Insert Nice at index 2 i.e., at position 3 in list.

index=planetName.index("Earth")-1

planetGravitationalForce.insert(2,5*planetGravitationalForce[index]) #insert gravity of Nice in its list
weightOnPlanet.insert(2,10*weightOnPlanet[index]) #insert weight of Nice in its list.

for i in range(len(planetName)):
print("Planet Name=", planetName[i]) #print the data after insertion of Nice
print("Gravitational Force=", planetGravitationalForce[i])
print("Weight=", weightOnPlanet[i])

Screenshot:

The screenshot of the program is attached below along with the output generated.

Please follow the below screenshot for proper indentation.

See that the gravitational values for planets are nor correct. They are some random values entered in the list.


Related Solutions

PYTHON Write a program that accepts a range of input from the user and checks whether...
PYTHON Write a program that accepts a range of input from the user and checks whether the input data is sorted or not. If the data series is already sorted your program should print “True” or should print “False” otherwise. You should not use any sort function for this program. Input: How many numbers you want to input: 3 # user input 3 Input the number: 5 Input the number: 2 Input the number: 7 Output: False
python: ask the user to input a sequence of positive numbers. the end of the sequence...
python: ask the user to input a sequence of positive numbers. the end of the sequence is determined when the user enters a negative number. print out the maximum number from the sequence. output: keep entering positive numbers. to quit, input a negative number. enter a number: 67 enter a number: 5 enter a number: 8 enter a number: -3 largest number entered: 67 (note: i do not want to ask the user how many numbers they will input)
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
Design a Python script that accepts as input a user-provided list and transforms it into a...
Design a Python script that accepts as input a user-provided list and transforms it into a different list in preparation for data analysis, the transformed list replaces each numeric element in the original list with its base-10 order of magnitude and replaces string elements with blanks. Example: This script accepts as input a user-provided list expected to contain non-zero numbers and strings. It then prints a transformed list replacing numbers with their order of magnitude, and strings as blanks. Type...
Python! Create a program that does the following: Reads a number from the user. Calls a...
Python! Create a program that does the following: Reads a number from the user. Calls a function that finds all the divisors of that number. Calls another function to see if the number 7 is a divisor of the original number. Keeps reading input from the user and calling the function above until the user enters the letter ‘q’. Create 2 functions findDivisors() and lucky7(). Use docstrings to explain what each function does. Use the help() function to output the...
modify the code below to create a GUI program that accepts a String from the user...
modify the code below to create a GUI program that accepts a String from the user in a TextField and reports whether or not there are repeated characters in it. Thus your program is a client of the class which you created in question 1 above. N.B. most of the modification needs to occur in the constructor and the actionPerformed() methods. So you should spend time working out exactly what these two methods are doing, so that you can make...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input...
PYTHON Write a python program that encrypts and decrypts the user input. Note – Your input should be only lowercase characters with no spaces. Your program should have a secret distance given by the user that will be used for encryption/decryption. Each character of the user’s input should be offset by the distance value given by the user For Encryption Process: Take the string and reverse the string. Encrypt the reverse string with each character replaced with distance value (x)...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Need this program in python. The data must be taken from user as input. Write a...
Need this program in python. The data must be taken from user as input. Write a program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert. The conversion formula is: Miles = Kilometers X 0.6214 Kilometers = Miles / 0.6214 Write two functions that each accept a distance as an argument, one that converts from Miles-to-Kilometers and another that converts from Kilometers-to-Miles The conversion MUST be done...
Create the logic for a rhyming program that takes in five words from a user input...
Create the logic for a rhyming program that takes in five words from a user input and replaces the selected rhyming words with the user's input, then creates and displays the Humpty Dumpty rhyme with the five words from the user input. Hint: 1. You will use the sentinel values: start and stop 2. The program will ask the user for 5 words. 3. The program will store the 5 words 4. The program outputs the rhyme replacing the ____...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT