Playing with Numbers in Python – 1

#---------------------------- finding Sum and Product of n numbers --------------------------

nums =[] #initializing empty list to get elements
n1 = int(input("Enter the no.of elements : ")) # no. of elements
add =0  
mul =1
for i in range(n1):
    print(i+1,"Enter number :",end='')
    ele =int(input())
    nums.append(ele)
    add += nums[i]  # adding all element in list
    mul *= nums[i]  # multiplying all element in list
print("The sum is : ",add)
print("The product is : ",mul)

#---------------------------- finding Sum and Difference numbers -----------------------------

n1 = eval(input("Enter 1st number :"))
n2 = eval(input("Enter 2nd number :"))
n3 = eval(input("Enter 3rd number :"))
n4 = eval(input("Enter 4th number :"))
add= (n1+n2),(n3+n4)
sub =(n1-n2), (n3-n4)

print("\nSum : (",n1,"+",n2,",",n3,"+",n4,") =",add) #print("Sum : ",add)
print("\nDifference : (",n1,"-",n2,",",n3,"-",n4,") =",sub) # print("difference :",sub)
#---------------------------- finding  positive, negative of numbers -------------------------

n1 = int(input("Enter 1st number :"))
n2 = int(input("Enter 2nd number :"))

if(n1 == 0 & n2 ==0 ):  # checking for zeros
    print("All are zero.")
if(n1 == n2 & n2==n1):  # checking for equality
    print("All are Equal")

# Checking for negative
if(n1<0 or n2<0 ):  
    if(n2<0 ):
        print("2nd number",n2,"is negative")
    if(n1<0 ):
        print("1st number",n1,"is negative")
    else:
         print()

# Checking for positive

if(n1>0 and n2>0 ):
    print("All are postive")
if(n1>0 or n2>0 ): # Checking for positive
    if(n1>0 ):
        print("1st number",n1,"is Positive")
    if(n2>0 ):
        print("2nd number",n2,"is Positive")
    


 
#---------------------------- n numbers of elements --------------------------------------

n =int(input("Enter the no.of numbers :"))
for i in range(1,n+1):
    print(i,end=' ')
#---------------------------- count numbers of elements of given range------------------------

sn =int(input("Enter the start number :"))
en =int(input("Enter the end number :"))
count =0
for i in range(sn,en+1): # range from start to  end+1
    print(i,end=' ')
    count+=1
print("\nNo. of element : ",count)
#---------------------------- check whether given number can form triangle -------------------

num = int(input("Enter a number :"))
p=0
i=1
while(num>=p):
    if(num==p):
        print("\ncan form Triangle" )
    p+=i
    i+=1
 

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available