Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. List, Tuples and Dictiona...
  5. Illustrative Problems &#8...
  6. Additional Programs

Additional Programs

Problem

An email address is provided

hello@python.org Using tuple assignment, split the username and domain from the email address.
addr = "hello@python.org"
username, domain = addr.split('@')
print("username=", username)
print("domain=",domain)

Output

username= hello
domain= python.org

Write a function called sumall that takes any number of arguments and return sum

def sumall(*tuple1):
    i=0
    sum=0
    while i<len(tuple1):
        sum=sum+tuple1[i]
        i=i+1
    return sum
ans=sumall(2,3,4,5,6,1)
print("result is:", ans)

Output

result is: 21

Write a function called circleinfo which takes the radius of circle as argument and returns the area and circumference of the circle

def circleinfo(r):
	cir = 2 * 3.14 * r
	area = 3.14 * r * r
	return (cir, area)

rad = int(input('Enter radius:'))
tup = circleinfo(rad)
(c,a) = tup
print("Circumference = ", c)
print("Area =",a)

Output

Enter radius:3
Circumference =  18.84
Area= 28.259999999999998

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments