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

  Implement a battleship game in python

Assignment Summary: Battleship is a children's game where players guess (x,y) coordinate positions of the opposing player's ship pieces in a 10x10 grid. For the official Hasbro rules and additional game context, read http://www.hasbro.com/common/i..

  Implement a voting test

Implement a voting test. The user enters their age and then the program prints either, "You must be 18 to vote" or "You are of voting age"

  Write a class named animal with the following attributes

InfoTc 1040 Introduction to Problem Solving and Programming-Write a class named Animal with the following attributes and methods.

  Program that creates a dictionary containing

Write a program that creates a dictionary containing the U.S. states as keys and their capitals as values. The program should then randomly quiz the user by displaying

  Explain the purpose of significant code segments

IFN680 - Advanced Topics in Artificial Intelligence - Queensland University of Technology - implement a probability-based approach to allow the agent to explore

  Write a short program in python that turns on all leds

Write a short program in Python that turns on all LEDs, one at a time, in a looping fashion. When an LED is on, it should stay on for 1 second.

  Calculate the sum of the first n odd numbers

A program that ask the user for a username and password and read the names and password from a text file, if the username and password match.

  Program that asks the user to enter a students name

The program should output the students name, a letter grade for each assignment score, and cumulative average for all the assignments

  Write a simple python program

Write a simple python program that takes use inputs as non-zero digits and converts them into binary form. The response must be typed.

  Adopt a service oriented architecture

adopt a Service Oriented Architecture (SOA) for its future IT infrastructure. Queensland Health executives were impressed with your Template based, Reference

  Define a recursive function that finds the result of string

Define a recursive function that finds the result of an arithmetic string. The given string will contain numbers, operators and possibly spaces.

  MAE 3403 Computer Methods in Analysis and Design Assignment

MAE 3403 Computer Methods in Analysis and Design Assignment Help and Solution, Oklahoma State University - Assessment Writing Service

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