Write a python program that computes the summation

Assignment Help Python Programming
Reference no: EM133059356

Learning Activity: Programming Exercises

Exercise 1. Find a particular number in a random list (return index)

NOTE: this learning activity requires Python 3.6 or higher. In Module 1.1, you were asked to install any Python version higher than 3.6. If you use a version lower than Python 3.6, some of the code will not work.

Following the previous learning activity, you will now implement something slightly more advanced. Implement a linear search algorithm, but this time, if you find the number in the list, return the index of that number, otherwise, return -1.

Once again, your program will first start with the following two lines of code: import random
l = random.choices(range(100), k = 50)

For example, this sequence could be generated by these two lines of code:
[16, 56, 85, 8, 98, 50, 71, 81, 56, 12, 75, 24, 10, 60, 38, 25, 7, 98, 89, 3, 89, 27, 69, 46, 14, 15, 23, 15, 22, 47, 8,
81, 24, 94, 97, 40, 69, 2, 29, 59, 44, 32, 69, 37, 53, 91, 46, 14, 72, 94]

You now need to ask the user the type in a number, then perform a linear search over the random list l. If you can find the number from the list, then output the index of that number, otherwise output -1.

For example, if user type in 50, you should output 5. 5 is the index of number 50 in the list. If user types in 100, you should output -1 as you cannot find 100 in the list.

Sample input/output:
>>> Enter a number:
>>> 100
>>> -1

Sample input/output:
>>> Enter a number:
>>> 56
>>> 1

This learning activity asks you to write a program.

Please upload your code as a Python code file (.py file) to Module 3.1 Programming Exercise - Medium Difficulty Discussion Forum and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.

Please check other students' code and comment on why you agree, disagree or can provide help with another students' post. Please reply to at least two other students' posts.

Exercise 2. Summation

Write a Python program that computes the summation from 1 to a given number. That is, for a given number n, calculate:

i=1n

i = 1 + 2 + 3 + ....+ (n-1) + n

Your program should first ask the user to type in a positive integer, your program will then calculate the summation from 1 to that number (inclusive). For example, if the user types in 6, your program should output 21. If the user types in 100, your program should output 5050. You cannot use the sum() function in this exercise.

Sample input/output:
>>> Enter a positive number:
>>> 1000
>>> 500500

This learning activity asks you to write a program.

Please upload your code as a Python code file (.py file) to Module 3.1 Programming Exercise - Medium Difficulty Discussion Forum and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.

Please check other students' code and comment on why you agree, disagree or can provide help with another students' post. Please reply to at least two other students' posts.

Exercise 3. Factorial

Write a Python program that computes the product from 1 to a given number. That is, for a given number n, calculate:

ni=1 i = 1 x 2 x 3 x .... x (n-1) x n

Your program should first ask the user to type in a positive integer, your program will then calculate the product from 1 to that number (inclusive), that is the factorial of that number. For example, if the user types in 6, your program should output 720. If the user types in 20, your program should output 2432902008176640000.

Sample input/output:
>>> Enter a positive number:
>>> 5
>>> 120

This learning activity asks you to write a program.

Please upload your code as a Python code file (.py file) to Module 3.1 Programming Exercise - Medium Difficulty Discussion Forum and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.

Please check other students' code and comment on why you agree, disagree or can provide help with another students' post. Please reply to at least two other students' posts.

Exercise 4. Square numbers

Write a Python program that allows the user to type in a number, then outputs all square numbers that are smaller or equal to that number starting from 1, separated by comma. For example, if the user type in number 20, your program then should output 1, 4, 9, 16.

Sample input/output:
>>> Enter a positive number:
>>> 100
>>> 1, 4, 9, 16, 25, 36, 49, 64, 81, 100

Reference no: EM133059356

Questions Cloud

How much would Ramiro adjust its investment in Marco Company : Marco reported net income of $74,200 and declared dividends of $20,300 during the year. How much would Ramiro adjust its investment in Marco Company
What would be an approximate market price per share : If the common stock had a market price of $140 per share before the stock split, what would be an approximate market price per share after the split
Briefly define the term accountability : Briefly define the term accountability and explain why the notion of social and environmental accountability is a greater focus of accounting today
What is the value of HBB Company : HBB Company for the last ten years, has earned and had cash flows of about Php 500,000 every year. What is the value of HBB Company
Write a python program that computes the summation : Find a particular number in a random list - Implement a linear search algorithm, but this time, if you find the number in the list, return the index
What are the possible consequences : Question - Read the Ethical Issue case about Becky Knauer and her position with Mueller Imports. What are the possible consequences
Programming Exercise - Fibonacci series : Programming Exercise - Fibonacci series - write a Python program that allows the user to type in an integer n. Your program will then output the first n terms
Write a python program that outputs all the even numbers : Write a Python program that outputs all the even numbers from 2 to a number (inclusive) provided by the user, separated by comma
Draw a flowchart and write up some pseudocode : Draw a flowchart and write up some pseudocode for searching for a particular element in an arbitrary list.

Reviews

Write a Review

Python Programming Questions & Answers

  Create a program to create a program that adds the numbers

Create a program to create a program that adds the numbers 1/2 to itself and 1/3 to itself a large number of times. It is to then compare the values.

  Write a program that asks the user to enter a name

Asks the user to enter a name, age, and sex and allow the user to enter data for individuals as long as they would like provide them.

  Accept input of the name of the grocery item purchased

Using the update function to update the dictionary entry which contains the name, number and price entered by the user. Accept input of the name of the grocery

  How many grains of wheat would be on the chessboard

There is a famous puzzle intended to demonstrate the surprising growth of exponential sequences, sometimes called the "Wheat and chessboard problem."

  Calculate the final charge of a product at a retail store

Design a python program to calculate the final charge of a product at a retail store. You must also create flowcharts for each function and for the program.

  Create a list that contains the months of the year

Create a list that contains the months of the year? Create a loop to print the month number and name? The response paper should be in APA format.

  How many times does the body of the while loop repeat

How many times does the body of the while loop repeat? What is the output of each loop? Write a program which gives the option between doing 3 things.

  Write a program that computes the circumference of a circle

Write a program that computes the circumference of a circle with a radius of 7.5 and prints out the result. The circumference is 2* pi * radius.

  Write a python run test page

Write a python run test page. The run-test page will receive a data.csv from a configure page. The video is only to show you the whole project

  Simulate a tally counter that can be used to admit a limited

Simulate a tally counter that can be used to admit a limited number of people. First, the limit is set with a call def setlimit self, maximum.

  Convert inches into yards feet and inches

Convert inches into yards, feet, and inches

  Create the flowchart for the program in a word document

Create two parallel arrays that represent a standard deck of 52 playing cards. Create the flowchart for the program in a Word document.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd