(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Python program to print sum of first and last digit of a number. - TecGlance

Header Ads

Python program to print sum of first and last digit of a number.

Algorithm:::




Step 1: Read a number, num
Step 2: Compute num1=num%10
Step 3: Assign num2=num
Step 4: Repeat step 5 while num2=>10
Step 5: Compute num2=num2/10
Step 6: print num1+num2
Step 7: Stop


Flowchart:::


Program code:::

num=int(input('Enter a number '))
num1=num%10;
num2=num
while num2>=10:
    num2=num2/10;
print num1+num2



2 comments:

  1. Glad you used a semicolon in a python program

    ReplyDelete
  2. Read any 3 digit number from user and display sum of first and last digit of the same

    ReplyDelete

Powered by Blogger.