Write a program that creates an array called temperatures and then add five temperatures input from the keyboard. Then, print the array.
Sample Run
Enter a temperature: 45
Enter a temperature: 67
Enter a temperature: 89
Enter a temperature: 47
Enter a temperature: 89
[45, 67, 89, 47, 89]

Answer :

Answer:

temperatures = []

number1 = int(input("Enter a temperature: "))

number2 = int(input("Enter a temperature: "))

number3 = int(input("Enter a temperature: "))

number4 = int(input("Enter a temperature: "))

number5 = int(input("Enter a temperature: "))

temperatures.append(number1)

temperatures.append(number2)

temperatures.append(number3)

temperatures.append(number4)

temperatures.append(number5)

print ("Enter a temperature: " + str(number1))

print ("Enter a temperature: " + str(number2))

print ("Enter a temperature: " + str(number3))

print ("Enter a temperature: " + str(number4))

print ("Enter a temperature: " + str(number5))

print (temperatures)

Explanation:

The program that creates an array called temperatures and then add five temperatures input from the keyboard. Then, print the array is as follows;

temperature = []

length = 0

while length < 5:

    x = input("Enter a temperature: ")

    length += 1

    temperature.append(x)

print(temperature)

Code explanation

The code is written in python.

  • The first line of code, we initialise an empty array where the temperature reading will be stored.
  • Then we also initialise the variable length to 0.
  • Then, we use while loop to loop five time through the users input.
  • Then add to the length in each loop.
  • Then we append the users input to the empty array.
  • Finally, we print the temperature readings.

learn more on array here:https://brainly.com/question/20379340

${teks-lihat-gambar} vintechnology
${teks-lihat-gambar} vintechnology

Other Questions