Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7495245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:00:27+00:00 2026-05-29T18:00:27+00:00

I am trying to learn python, I was trying write C/C++ code i used

  • 0

I am trying to learn python,
I was trying write C/C++ code i used before in python, can anyone help me find whats wrong in this code….

#print 1st for 1 -> st or 2nd for 2 -> nd , etc

x = int(input('Enter a number :'))
temp = x
while temp>0:
    temp = temp % 10

if temp == 1:
    print (x, "st")
elif temp == 2:
    print (x, "nd")
elif temp == 3:
    print (x, "rd") 
else:
    print (x, "th")

and can you suggest few goods books to learn python, for now i was reading the documentation and its not for beginners…and i know C/C++

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:00:29+00:00Added an answer on May 29, 2026 at 6:00 pm

    Let’s see how this:

    temp = x
    while temp>0:
        temp = temp % 10
    

    works, using an example (x=12345).

    temp = 12345
    12345>0
    temp = 12345%10 = 5
    5>0
    temp = 5%10 = 5
    5>0
    temp = 5%10 = 5
    ...
    

    So it’s an endless loop!

    To get the last digit (which is probably what you want) just do this:

    temp = x%10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to learn Python lists. In this code I am trying to
I'm trying to learn python, so I decided to write a script that could
Trying to learn Regex in Python to find words that have consecutive vowel-consonant or
I'm trying learn Python (3 to be more specific) and I'm getting this error:
I am used to programming in python and am trying to learn javascript. I
This probably measures how pythonic you are. I'm playing around trying to learn python
I'm trying to learn python and I'm attempting a hangman game. But when I
I am trying to learn python and am making a program that will output
I'm trying to learn python. I am using 3.1.2 and the o'reilly book is
I am trying to learn how Python reloads modules, but have hit a roadblock.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.