Question
use python code complete this question

Assignment 3 o Get information until getting n from user Input the name of 1th student : 84 Input the math score of 1th st
Assignment 3 o Get information of students from input • Name - Math score - English score - Science score O Save scores to a
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

import pandas as pd
import numpy as np
print("Hello World")
name_list=[]
maths_list=[]
english_list=[]
science_list=[]
i=1
while True:
    name=input("Enter the details of "+str(i)+"th student :")
    maths=int(input("Enter the math score of "+str(i)+"th student :"))
    english=int(input("Enter the english score of "+str(i)+"th student :"))
    science=int(input("Enter the science score of "+str(i)+"th student :"))
    name_list.append(name)
    maths_list.append(maths)
    english_list.append(english)
    science_list.append(science)
    i=i+1
    choice=input("keep moving y/n?")
    if choice=="n":
        break
dictionary1={"name":name_list,"english":english_list,"maths":maths_list,"science":science_list}
print(dictionary1)
df1=pd.DataFrame(dictionary1)
print(df1)


textfile = open('class.txt', 'a')
textfile.write(df1.to_string(header=True,index=False))
textfile.close()

Explanation:

First we need to declare 4 empty lists.one is used to store the students name and remaining 3 lists are used to store the subjects scores.

Initially we don't know number of students .It depends upon the user choice.If user's choice is n then we need to beak the while loop,otherwise we need to continue the iteration.i value is 1 and we need to take 4 inputs from the user.The input we are receiving from the user will be in string format.So we are converting marks to int type.we are appending name into name list and scores into corresponding scores list and increment the i value by 1.We need to ask if the user want to continue or not by taking the input .if the input string is "n" then the loop will break automatically otherwise it will continue.

Once we are exited from the while loop.We need to create a dictionary for storing values in the data frame.Once we have stored all the values in the data frame ,we can directly dump those values into the text file.

Data frame stores values in a tabular format(Rows and columns). Each row is having index and that will contain related data of a student.

open() function will create a text file .we can write the data frame into the text file by eliminating the indexes.

Note:still if you found any queries,let me know.Thank you

Add a comment
Know the answer?
Add Answer to:
use python code complete this question 'Assignment 3 o Get information until getting 'n' from user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use PYTHON Assignment 4 O Let's make random IDs. Get the number of IDs from the...

    use PYTHON Assignment 4 O Let's make random IDs. Get the number of IDs from the user to make from the keyboard. Then print the IDs. O Note that the IDs should be unique. Moreover, one ID is 11-length alphabet characters including digits (i.e., A-Z, A-Z, 0-9). Template Code Example import string import random num_of_ids = int(input("Enter the number of IDs: ")) # this list contains a-z, A-Z, and digits alphabet_digit_list = string.ascii_letters + string.digits Enter the number of IDs:...

  • **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the...

    **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the creatures from the classic science-fiction film "The Day of the Triffids") is an algorithm that enciphers a plaintext message by encoding each letter as a three-digit number and then breaking up and rearranging the digits from each letter's encoded form. For this assignment, you will create a set of Python functions that can encode messages using this cipher (these functions...

  • Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in...

    Assignment Predator / Prey Objectives Reading from and writing to text files Implementing mathematical formulas in C++ Implementing classes Using vectors Using command line arguments Modifying previously written code Tasks For this project, you will implement a simulation for predicting the future populations for a group of animals that we’ll call prey and their predators. Given the rate at which prey births exceed natural deaths, the rate of predation, the rate at which predator deaths exceeds births without a food...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT