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

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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