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

  • SEARCH
  • Home
  • 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 9052693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:14:28+00:00 2026-06-16T13:14:28+00:00

Can someone please explain how this code is working for me? I don’t understand

  • 0

Can someone please explain how this code is working for me?
I don’t understand it from the try command down.
This while loop is working for me. However I do not understand how all of it works.

price = 110 #this i get
ttt = 1 #this i get

while price< 0 or price> 100: #this i get
    if ttt >=2: #this i get
        print "This is an invalid entry" #this i get
        print "Please enter a number between 0 and 100" #this i get
    try: #From here i do not understand , but without it, it does not work
          price= int(raw_input("Please enter the price : "))
    except ValueError:
      price = -1   
    ttt +=1

As I’m a learner I don’t really want a more complicated way to do it.
I just want to fully understand what’s happening in the loop.

  • 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-06-16T13:14:29+00:00Added an answer on June 16, 2026 at 1:14 pm

    A try statement is a way to catch you code before it crashes, or exits do to an uncaught exception. Some functions may throw errors that can cause an application to crash/force quit, and the try block takes thoses would-be-errors, and lets you do something about it.

    i.e. -> An app that is trying to open a log file, but no file is found…

    UnCaught: Force-quite, IOException.
    Caught: Execute another block of code that creates the file.

    In your example, it will take raw data from the prompt, and assign it to an integer value… however abc can not be converted to an integer, so it would normally crash… Inside of a TRY block, it will return a -1, saying that it did not recieve a result that it was expecting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please try and explain this code for me, I don't really understand
Can someone please explain why I'm getting this error Type mismatch: cannot convert from
Can someone please explain why this JavaScript code outputs zero instead of one? Also,
this is absolutely driving me crazy! Can someone please explain why this code isn't
Can someone please explain why this code: $str = StackOverflow; echo $str . -
Can someone please explain this bit of piece of code? Thanks. alert({foo:test foo, bar:test
Can someone please explain this piece of code? struct Class { boost::function<void()> member; };
Can someone please explain this phenomenon? I am using Mojarra 2.1.6 - Glassfish 3.1.2.
Can someone please explain to me how this responsive approach works? This was done
I have a feeling this XML is not valid, can someone please explain why?

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.