Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Give the Python program that computes the square of a number. The number is passed to the function as a parameter. The output is

1. Give the Python program that computes the square of a number. The number is passed to the function as a parameter. The output is the square of this number. For example, the function can be used as shown below

. . . .

n = s q u a r e ( 7 )

. . .

2. Another very useful feature of Python is looping, which is more flexible than that available in BB.

For example:

while i <10:

p r i n t ( i )

will give the following output:

0

1

2

3

4

5

6

7

8

9

In this experiment, give the Python program that outputs the sum of squares of numbers from 1 to n, i.e. y = 12 + 22 + 32 + ... + n2

where n is specified by the user at run time.

Hints:

y can be computed using a loop, say, while.

Before you can use the while loop, you need to initialize y with 0.

In the ith iteration of the loop, add i2 to y, i.e. y = y + i2 .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago