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
kenny6666 [7]
3 years ago
7

Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done

, report to the user the position of the first 7 entered and the last 7 entered. By position we mean, for example, that if the first 7 is the 2nd number entered then its position would be 2.

Computers and Technology
1 answer:
KATRIN_1 [288]3 years ago
7 0

Answer:

<em>The program written in Python 3 is as follows;</em>

<em>The program does not make use of comments; however, see explanation section for detailed line by line explanation of the program</em>

num = int(input("Number of Inputs: "))

mylist = []

userinput = int(input("Enter a digit: "))

i = 1

while i < num:

     mylist.append(userinput)

     userinput = int(input("Enter a digit: "))

     i += 1

   

try:

     first7 = mylist.index(7)+1

     print('The first position of 7 is ',first7)

     last7 = num - 1 - mylist[::-1].index(7)

     print('The last position of 7 is ',last7)

except:

     print('7 is not on the list')

Explanation:

This line prompts user for the number of inputs

num = int(input("Number of Inputs: "))

This line declares an empty list

mylist = []

This line inputs the first number into the empty list

userinput = int(input("Enter a digit: "))

The italicized lines represent an iteration that allows user to input the numbers into the empty list.

<em>i = 1</em>

<em>while i < num:</em>

<em>      mylist.append(userinput)</em>

<em>      userinput = int(input("Enter a digit: "))</em>

<em>      i += 1</em>

The try-except is used to check the presence of 7 in the list

try:

This checks the first occurrence of 7

     first7 = mylist.index(7)+1

This prints the first occurrence of 7

     print('The first position of 7 is ',first7)

This checks the last occurrence of 7

     last7 = num - 1 - mylist[::-1].index(7)

This prints the last occurrence of 7

     print('The last position of 7 is ',last7)

The following is executed if there's no occurrence of 7

except:

     print('7 is not on the list')

See Attachments for sample runs

You might be interested in
The system should enable the staff of each academic department to examine the courses offered by their department, add and remov
Ganezh [65]

Answer:

See attached picture.

Explanation:

See attached picture.

3 0
3 years ago
In cell K26, create a formula that counts the number times "Thunder" occurs in the columns containing "Names"
jek_recluse [69]

Answer:

I1 to K2: Use a formula to link the cells. Create a formula in column L that calculates the averages for each matching category in K2:

<h3>hope it's help you </h3><h3>plz mark as brain list </h3>
3 0
3 years ago
A user reports that a file they shared out on their computer for another network user is not accessible to the third party. The
muminat

Answer:

i think it's going to be c

Explanation:

3 0
3 years ago
Which of the following, when used in conjunction with hyperlinks, can be useful for easily navigating a Word document? : *
Valentin [98]
Caption is a best answer i hope its work
7 0
3 years ago
Select the correct answer.
8090 [49]

Answer:

Definitally c

Explanation:

6 0
2 years ago
Other questions:
  • For C++ (please make sure it runs properly)
    14·1 answer
  • Which of the following applications can be used as a data source for a Microsoft® Word® mail merge? A.Outlook Contacts B.Microso
    9·2 answers
  • Will upvote all answers
    7·1 answer
  • How does a spreadsheet affect a column of numerals when it sorts the column
    15·2 answers
  • Ashley works for a movie theater. The theater has decided to host some special events over the summer. She needs to communicate
    8·2 answers
  • What property of semi-metals is useful in the computer industry?
    7·1 answer
  • Jim wants to buy a car, but he’ll probably only need it for a couple of years. He has a short commute to work, so he won’t be pu
    10·1 answer
  • A-1 grdening supply is preparing a reprt to hand out to the customerez in pointes form only.why should the reprts writers avoid
    9·2 answers
  • What is the answer for 2.8.10 word games? This is what I have so far, but I can’t seem to be able to figure out the bananaSplit
    6·1 answer
  • Which action does not happen in each iteration of the repeat loop in the
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!