1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kotykmax [81]
3 years ago
14

Write a loop to print all elements in hourly_temperature. Separate elements with a -> surrounded by spaces. Sample output for

the given program: (must be in python)
90 -> 92 -> 94 -> 95
Note: There is a space after 95.
------------------------------------------------------------------------------------------------------------------------
hourly_temperature = [90, 92, 94, 95]
for temp in hourly_temperature:
for index,temp in enumerate(str(temp)):
if index != len(temp)-1:
print(temp,'->',end=' ')
else:
print(temp, end='')
print('') # print newline
------------------------------------------------------------------------------------------------------------------------
My expected out is:
90 -> 92 -> 94 -> 95
I keep getting:
90 -> 92 -> 94 -> 95 ->
NOTE: I can't edit the last line "print('') #print newline"
Computers and Technology
1 answer:
kaheart [24]3 years ago
4 0

Answer:

Following are the code to this question:

hourly_temperature = [90, 92, 94, 95]#defining a list that holds values

c= 0#defining a variable c

for temp in hourly_temperature:#defining a for loop to count list values

   c+= 1#defining c variable to increment the value of c

   for index,temp1 in enumerate(str(temp)):#defining for loop for spacing the list value

       if index == len(str(temp))-1 and c!= len(hourly_temperature):#defining if block that checks the length of list

           print(temp1,'->',end=' ')#print value

       elif c == len(hourly_temperature) and index == len(str(temp)) - 1:#defining elif block that checks the length of list

           print(temp1, end=' ')#print value

       else:#defining else block

           print(temp1, end='')#print value

Output:

90 -> 92 -> 94 -> 95  

Explanation:

In the above-given code, a list "hourly_temperature" is declared, in which an integer variable c is declared, that holds an integer value that is equal to 0, and two for loop is declared, and in the first loop is used for count list value, and inside the for loop is uses enumerate method to assigns an index for each item and use the conditional statement to check each list value and provide space in each element value.

You might be interested in
What is a written or electronic document that outlines etiquette policies for using networks and network resources?
daser333 [38]

Acceptable Use Policy is a written or electronic document that outlines etiquette policies for using networks and network resources.

Therefore, the answer is Acceptable Use Policy.

3 0
3 years ago
CHALLENGE ACTIVITY 4.2.2: Basic while loop with user input. Write an expression that executes the loop while the user enters a n
tino4ka555 [31]

Answer:

#include<iostream>

using namespace std;

int main()

{

int userNum;

userNum=9;

while(userNum>=0)

{

  cout<<"Body"<<endl;

  cin>>userNum;

}

cout<<"Done"<<endl;

return 0;

}

Explanation:

  • Use the userNum >= 0 expression that executes the loop while the user enters a number greater than or equal to 0.
  • Print the userNum inside the while loop.
3 0
3 years ago
Why computer known as tool of information​
S_A_V [24]

Answer:

because it has the ability to capture the whole information you need or downloaded

8 0
2 years ago
When creating any digital work, what is the MOST important thing to remember?
kvasek [131]

Answer:

ALWAYS  double check your work

Explanation:

3 0
3 years ago
In this problem, we explore some of the properties of the CRC. For the generator G (=1001) given in Section 5.2.3, answer the fo
allochka39001 [22]

Answer:

b

Explanation:

5 0
3 years ago
Other questions:
  • Explain why the control bus is not a bus.
    7·1 answer
  • What tasks do most operating systems perform?
    15·1 answer
  • What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y z * 2;
    14·1 answer
  • Primary technology skills are skills that are necessary for success in online education
    9·2 answers
  • Why might reading a product review be a good idea before purchasing a product?
    5·2 answers
  • Describe how you would create a Java program that prompted the user to correctly enter a username and password. The username is
    7·1 answer
  • Which of the following statements holds true for the term plug-in? Group of answer choices It refers to a program (typically a m
    11·1 answer
  • Which is an example of machine-to-machine communication?
    7·1 answer
  • _______ is a medium-range wireless network. ________ is a medium-range wireless network. Cellular radio LTE UWB Wi-Fi
    12·1 answer
  • Which iteration must have an expression that has a true or false value?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!