Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
a=int(input("Enter the number- "))
n1=int("%d"%a)
n2=int("%d%d"%(a,a))
n3=int("%d%d%d"%(a,a,a))
print(n1)
print(n2)
print(n3)
print ("Sum- ",n1+n2+n3)


What I have tried:

Pls help It has been taught us in the school but at that time I was absent?
Posted
Updated 7-Aug-21 21:40pm
v2

1 solution

Quote:
n2=int("%d%d"%(a,a))

takes the string representation of a, concatenates it with itself (2 instances), then takes the number corresponding to the resulting string.
e.g. a = 10 => n2 = 1010

The other statements are similar.
 
Share this answer
 
Comments
Patrice T 8-Jul-21 17:13pm    
+5
CPallini 9-Jul-21 1:55am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900