Question

# Write PYTHON programs that read a sequence of integer inputs and print # a.  The...

# Write PYTHON programs that read a sequence of integer inputs and print # a.  The smallest and largest of the inputs. # b.  The number of even and odd inputs. # c.  Cumulative totals. For example, if the input is 1 7 2 9, the program should print # 1 8 10 19. # d.  All adjacent duplicates. For example, if the input is 1 3 3 4 5 5 6 6 6 2, the # program should print 3 5 6.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#code.py
def calculate(lst):
    maxVal = lst[0]
    minVal = lst[0]
    evens = 0
    odds = 0
    for x in lst:
        if(maxVal < x):
            maxVal = x
        if(minVal > x):
            minVal = x
        if(x%2 == 0):
            evens += 1
        else:
            odds += 1
    print("Max =", maxVal)
    print("Min =", minVal)
    print("Evens =", evens)
    print("Odds =", odds)
    print("Cumulative total: ",end="")
    temp = 0
    for x in lst:
        temp += x
        print(temp, end=" ")
    pre = lst[0]
    i = 1
    print("\nAdjacent duplicates: ",end="")
    while i<len(lst):
        flag = False
        while(pre == lst[i] and i<len(lst)):
            pre = lst[i]
            i += 1
            flag = True
        if(flag):
            print(pre,end=" ")
        pre = lst[i]
        i += 1
    print("\n--------------------")

calculate([1, 3, 3, 4, 5, 5, 6, 6, 6, 2])
calculate([1, 7, 2, 9])

\color{red}\underline{Output:}

Max = 6 Min1 Evens 5 Odds 5 Cumulative total: 1 4 7 11 16 21 27 33 39 41 Adjacent duplicates: 3 5 6 Max9 Min = 1 Evens = 1 Cu

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
# Write PYTHON programs that read a sequence of integer inputs and print # a.  The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python 3 - Write a program that reads a sequence of integer inputs from the...

    In Python 3 - Write a program that reads a sequence of integer inputs from the user. When the user is finished entering the integers, they will enter a 'q'. There is no need to check if the entry is a valid integer. All integers in the test data (input) will be between -255 and 255. The program should then print: The smallest and largest of the inputs. The number of even and odd inputs (0 should be considered even)...

  • For Java Write a program that reads a sequence of integer inputs all on one line...

    For Java Write a program that reads a sequence of integer inputs all on one line and prints: 1.)The smallest and largest of the inputs 2.)The number of odd and even inputs 3.)Cumulative totals. If the input is 1 7 2 9, the program prints 1 8 10 19. 4.)All adjacent duplicates. If the input is 1 3 3 4 5 5 6 6 6 2, the output is 3 5 6.

  • Write a single program in java using only do/while loops for counters(do not use array pls)...

    Write a single program in java using only do/while loops for counters(do not use array pls) for the majority of the program and that asks a user to enter a integer and also asks if you have any more input (yes or no) after each input if yes cycle again, if not the program must do all the following 4 things at the end of the program once the user is finished inputting all inputs... a.The smallest and largest of...

  • IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we...

    IN PYTHON 1.Choose a positive integer 2. To get the next number in the sequence we do the following: If the integer is odd, we multiply by 3 and add 1. If the integer is even, we divide by 2. It is hypothesized that the above sequence will always converge to the value of 1, regardless of any valid initial choice. This hypothesis is known as the Collatz Conjecture. For example, if we start at 5, the numbers generated by...

  • python la ab X, X Lab 7 Design and implement a Python program that uses a...

    python la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...

  • Q1 SUMMER2020- nts python language Example Write a program to read an integer r then print...

    Q1 SUMMER2020- nts python language Example Write a program to read an integer r then print a triangle with r number of rows using .asterisks Result Input 5 Hint: Use end= parameter of the print function to not add a newline to the end of the string * * * * * * * * * * * * 9 - عام python language Course Information o Course Material Assignments o example input Lab Exercises Quizzes Result 7.0 ACUTE 7.0...

  • Write MARIE assembly language programs that do the following: I. Write a program that inputs thre...

    Write MARIE assembly language programs that do the following: I. Write a program that inputs three integers, a, b, and c, in that order. It computes the following ia-bi-fc+ c The result should be written to output 2. Write a program that inputs integers, s. y, and z. It outputs the difference of the langest and first element entered. You may assume x. y, and z all have different values. So if 8, 12, and 9 are input, the output...

  • CODE NEEDS TO BE IN PYTHON. OLA 5: Collatz Sequence Function 12 17 34 Due: Fri...

    CODE NEEDS TO BE IN PYTHON. OLA 5: Collatz Sequence Function 12 17 34 Due: Fri Oct 19, 2018 by 11:59 PM-may be tumed in until Oct 26 by 1159 PM with reduced points (per Open Lab- Project guidance found in the course syllabus) Assignment id: ola5 Assignment type: Project Required Files: ola5.py, myout.log Lab description: In this you will explore the Collatz mathematical sequence. This sequence eventually converges to the value 1, regardless of the initial input Requirements: 1....

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list : You are given a sequence of n positive integers a1,a2,…,an, where n is even. Swap adjacent elements in the given sequence and print the resulting sequence: a2,a1,a4,a3,a6,a5,… Input The first line contains a positive even integer n (2≤n≤1000) — the length of the sequence. The second line contains n space-separated integers a1,a2,…,an (1≤ai≤1000) — the elements of the sequence. Output Print n...

  • Write C program to take four integer inputs from user (A, B, C, D) then, your...

    Write C program to take four integer inputs from user (A, B, C, D) then, your program should return the sum of even numbers (if there any even numbers) and the multiplication of the odd numbers (if there any odd numbers). For example: if A=1, B=2, C=3, D=4, your program will return: sum=6, multiplication=3. if A=6, B=2, C=8, D=4, your program will return: sum=20, multiplication=0. if A=1, B=3, C=5, D=4, your program will return: sum=4, multiplication=15.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT