0% found this document useful (0 votes)
7 views

Mid Assignment CSE

cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Mid Assignment CSE

cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Answer to the Question no:1

There are 5 functions in this code:

input(): It takes user input as a string.

int(): It converts the input which is by default a string into an integer.

float(): It converts the integer to a floating-point number.

print():It displays the output to the user.

format(): It is used for string formatting. It replaces {0} with the value of
total.

Answer to the Question no:2

To find the average, I divided the total by the number of inputs (which is 3 in
this case).

Here is the updated code:

 I added the line average = total / 3 to calculate the average of the


three numbers.
 I then added print("The average of the three numbers is
{0}".format(average)) to display the calculated average.
Answer to the Question no:3

Yes, a list can be considered as a data structure. A list in Python is used to


store multiple items in a single variable. Lists are useful because :

 List can store and manage items. We can also change its elements
after they are created.

 List Can store a mix of data types like integers, strings, floats, etc.

Answer to the Question no:4


Here's an example of a student list with 3 attributes: ID, Name, and Grade.

Answer to the Question no:5


Printing the list in a way so that each item is printed with its attributes side

by side:

 I used a for loop to repeat over each item in the students list.
 I used range(0, len(students)) function to generate a sequence of
numbers starting from 0 to the length of the students list, minus one.
 Then I used print function to output the indexes, which contains the
attributes ID, Name, Grade and separated them by commas.
Answer to the Question no:6
Modifying the code with left to right/right to left spacing and the .format()
function:

 Here I used {0:1}: to align the ID with a width of 1 space.


 {1:10}: to align the Name with a width of 10 spaces.
 And {2:4}: to align the Grade with a width of 4 spaces.

Answer to the Question no:7


We need loop for printing the list because:

 A loop allows us to automate repetitive tasks without manually writing


a print statement for each item.
 Lists often contain many items, so using a loop ensures that we can
access and print each item regardless of the list’s length.

Answer to the Question no:8


Here is a question mind map on how we can solve this assignment:

1.Where should we
place the input() and 1.What is the task asking
print() functions in our us to do in each
code? Where What question?

2.Where can we 2.What Python


implement lists in real- structures or methods
Midterm
world scenarios?
Assignment
1. Why are we using lists
1.How do we format in Python?
output using .format() How Why
2.Why is a loop
in Python?
necessary for handling
2.How can we use multiple list items?
loops to print lists
When?
1.When should we use functions
like int() and float() in input
handling?

2.When is a loop necessary in a

You might also like