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 the difference between a hand-drawn sketch, a working drawing, and a 3D model?
vova2212 [387]
A hand draw sketch is drawing with just a pencil and paper. also work drawing is a drawing on at a job. The 3D sketch is on the computer.
7 0
4 years ago
What is the definition of a digital signal?
pashok25 [27]

Answer:

communication of the binary data via the voltage level for each time interval

Explanation:

5 0
3 years ago
Write c++ code that prints: usernum ... 2 1 blastoff! your code should contain a for loop. print a newline after each number and
nata0808 [166]
#include <iostream>
int main() { int usernum = 3;
for(int i = usernum; i >= 1; i--) { std::cout << i << "\n"; } std::cout << "blastoff!\n";
return 0;}
Works fine my dude:
./randombrainly 321blastoff!
3 0
4 years ago
Select the correct answer..
kicyunya [14]

Answer:

A mid shot or medium shot

Explanation:

4 0
3 years ago
How did the computer obtain its current ip address? how can you determine this
salantis [7]
Ip Adress is a one of a kind series of numbers isolated by periods that distinguishes every PC utilizing the Internet Protocol to convey over a system. These are the default setting when the PC can't discover a system and on the grounds that it is the Server's nearby IP.
4 0
4 years ago
Other questions:
  • Two electronics technicians are looking at the representations of a silver atom and a copper atom in the figure above. Technicia
    10·1 answer
  • Create a "web page" with the following components: An input field for the "number of rounds to play" The "number of remaining" r
    14·1 answer
  • What does the key combination ctrl+s achieve?
    7·2 answers
  • According to the 2010/2011 Computer Crime and Security Survey, ____ is "the most commonly seen attack, with 67.1 percent of resp
    10·1 answer
  • #Write a function called "in_parentheses" that accepts a
    5·1 answer
  • When discussing the data-modeling building blocks, anything (a person, a place, a thing, or an event) about which data are to be
    15·1 answer
  • Suppose you have the following declaration.char[] nameList = new char[100];Which of the following range is valid for the index o
    7·1 answer
  • ___________ is related to mass, but also includes the gravitational pull of the Earth.
    14·1 answer
  • ___________ are the constant values that are used in a program. ​
    14·1 answer
  • USE THIS CODE ON FETCH REWARDS FOR BRAINLIEST​ Also I will be doing a gift card giveaway for the ppl that use my code ​
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!