Monday, December 9, 2019

write a program to take a tuple of numbers from the keyboard and print sum ,avg

a=eval(input("Enter  some of tuple numbers"))
l=len(a)
sum=0
for x in a:
    sum=sum+x
print("The sum=",sum)
print("The avg=",sum/l)

output:
Enter  some of tuple numbers(10,20,30)
The sum= 60
The avg= 20.0

Tuple comprehension not support in python

a=(x*x for x in range(1,11))
#print(a)
for x in a:
    print(x)

output:
1
4
9
16
25
36
49
64
81
100

Write a program for tuple packing in python

Tuple packing:
====================================

t=(10,20,30,40)
a,b,c,d=t
print("a=",a,"b=",b,"c=",c,"d=",d)

output:
a= 10 b= 20 c= 30 d= 40



Tuple packing for strings:
==============================
t="abcd"
a,b,c,d=t
print("a=",a,"b=",b,"c=",c,"d=",d)

output:
a= a b= b c= c d= d

Perform Addition, Subtraction, Multiplication, Division and Modulus operation on two integers.


#include<stdio.h>
void main()
{ int a,b;
printf("\n enter two values: ");
scanf("%d %d",&a,&b);
printf("\n a + b = %d", a+b);
printf("\n a - b = %d", a-b);
printf("\n a * b = %d", a*b);
printf("\n a / b = %d", a/b);
printf("\n a modulus b = %d", a%b);
getch();
}




input:

 enter two values: 13  5

output:

 a + b = 18           
 a - b = 8
 a * b = 65
 a / b = 2
 a modulus b = 3

python class topic video