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 7601995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:18:01+00:00 2026-05-30T23:18:01+00:00

I am a beginner to python and any coding at all for that matter,

  • 0

I am a beginner to python and any coding at all for that matter, and I am having some trouble with some code I have written:

loop = 0
hellosentence = "You have selected the hello sentence"
questionsentence = "You have selected the question sentence"

usrinput  = raw_input("Which test would you like to bring up? ")

print eval(usrinput)+sentence

end = raw_input("Press any key to quit...")

I am trying to run the code with this in mind.

Have multiple names with sentence at the end.

Request which “sentence” the user wants to bring up

Once the user has typed in the sentence, it evaluates what they have typed, say “hello”
and combines it with “sentence” to make the variable “hellosentence”, thus bringing up the variable’s string.

I’m 14 and really trying to learn how to understand this language, so if anyone knows what I could do to fix this error, I would be very grateful.

  • 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-30T23:18:03+00:00Added an answer on May 30, 2026 at 11:18 pm

    eval is going to take the string you give it and evaluate it. In this case it’s taking the input string that was typed in. Judging by the variables you’ve defined, you want to take the input and append sentence to it, so if they type ‘hello’ you’ll return the value of hellosentence.

    The direct way to fix it is to give eval the proper input:

    print eval(usrinput+'sentence')
    

    That probably solves your problem, but it’s not a good way to do it. eval is the wrong tool for the job; error recovery is going to be a problem, and if this were production code you’d be opening a big hole for someone who wanted to turn your program into a virus.

    The proper tool is a dictionary, with which you can use the input to look up the proper output.

    selection = {'hello': hellosentence, 'question': questionsentence}
    print selection[usrinput]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

beginner to python here. I have 2 nested lists that I want to merge:
I am a complete beginner to Python or any serious programming language for that
As part of the last assignment in a beginner python programing class, I have
I've got a question related to a beginner Python snippet I've written to introduce
I am a beginner of python and have a question, very confusing for me.
First, let me say that I'm a complete beginner at Python. I've never learned
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
I'm quite new to threading in Python and have a couple of beginner questions.
I'm a beginner at using Python and I've been trying to code a Minesweeper
Dear all, I am beginner in Python. I am looking for the best way

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.