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
HURRY MY COMPUTER IS ABOUT TO DIE ILL GIVE BRAINLYESTn
loris [4]

Answer: D, C, E, are the answers! good luck.

Explanation:

5 0
3 years ago
Holly created a professional development plan to explore how she could advance from her entry-level position to the next step in
Sunny_sXe [5.5K]
A.) Ask a colleague for advice work life balance
3 0
3 years ago
Read 2 more answers
Write programs in python to display “Valid Voter”. (condition : age of person should be
muminat

Answer:

X = int(input("Age = ")

if (X >= 18):

print('Valid Voter')

Else:

return 0

Try it and let me know. :)

4 0
3 years ago
How do i get my laptop to connect to wifi?​
Rina8888 [55]

Answer:

open your laptop go to the wifi or service icon. Look for your wifi and put in the password

4 0
3 years ago
Read 2 more answers
Social media platforms are the only types of social media on the Web. True False
PIT_PIT [208]

Answer: true

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Users of an extranet can access a company or organization’s entire intranet
    8·2 answers
  • When using the strcat function, you must be careful not to overwrite the bounds of an array?
    5·1 answer
  • Does any one have 2 reasons it would be a good idea to have a glow in the dark TV.
    5·1 answer
  • Omega Software Inc. is currently running a training program for employees to upgrade their software skills so that they are able
    10·1 answer
  • PLEASE HELP
    11·2 answers
  • A Python keyword ______________.
    15·1 answer
  • Match the index with the value
    14·1 answer
  • Is a list of instructions an arguments?<br> Yes or No
    6·2 answers
  • Need comments added to the following java code:
    6·1 answer
  • True or false: Securing intellectual property digitally is the only security because that's how all IP is stored.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!