161k views
3 votes
Write notes on the following.

a. Write the syntax to create an array called marks with real number 56.5,92.8,80.0, 78.9 , and 95.0.
b. Write the Python program to create an array with five elements and read the elements from the keyboard and store it on the array.

User Dreanmer
by
7.9k points

1 Answer

4 votes

Final answer:

The syntax for creating an array called marks with specific real numbers in Python uses a list, e.g., 'marks = [56.5, 92.8, 80.0, 78.9, 95.0]'. For reading from the keyboard, use a loop to append user input to the list marks.

Step-by-step explanation:

To address part a, the syntax to create an array called marks with real numbers in Python can be achieved using the list data structure, as Python does not have a native array data type like some other languages. The following line of code accomplishes this:

marks = [56.5, 92.8, 80.0, 78.9, 95.0]

For part b, the Python program to create an array with five elements and read the elements from the keyboard is as follows:

marks = []
for i in range(5):
element = float(input("Enter mark {} ".format(i+1)))
marks.append(element)

This code creates an empty list called marks, then uses a for loop that runs five times, each time prompting the user to enter a mark which is then converted to a float and appended to the marks list.

User Reinaldo Junior
by
7.7k points