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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:57:50+00:00 2026-06-04T10:57:50+00:00

def ask(): global name, loca print What’s your name? name = raw_input(‘> ‘) print

  • 0
def ask():
    global name, loca

    print "What's your name?"
    name = raw_input('> ')
    print "Where are you from?"
    loca = raw_input('> ')

    if name or loca == None:
        print "Please enter valid details."
        ask()

ask()
print "Alright, so you're " + name + ", from " + loca + "."

With this script, it will only ever print the last line if both of my variables are empty. If I fill in one, or both, it triggers that if, making me redo the function.

What am I doing wrong here?

  • 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-04T10:57:51+00:00Added an answer on June 4, 2026 at 10:57 am

    You have very well isolated the problem:

    if name or loca == None:
    

    Here you think it says:

    "If either name or loca equal none:"
    

    But instead it says:

    "if (name) is true or (loca equals None) is true:"
    

    Where it should say:

    "if (name equals none) is true or (loca equals none) is true:"
    

    Which is:

    if name is None or loca is None:
    

    See, by the way, that None comparisons are better carried out with is, since there is only one None object.

    Also, a more pythonic way of doing it is:

    if not all((name, loca)):
    

    Or, seeing as “all” it’s just 2 variables:

    if not (name and loca):
    

    If you don’t understand, read around a bit (the Python tutorial is excellent — go for the conditionals part). Good luck!

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

Sidebar

Related Questions

I'll post my code first, and then ask questions. def menu(**arg): if len(arg) ==
def foo(**args): for k, v in args.items(): print type(k), type(v) for k, v in
I am new to Python so please don't flame me if I ask something
I need to ask a number from the user and have then if it
I am trying to join 2 strings using this code: def __get_temp(self): return float(self.ask('RS'))
by default, when i ask rails controller to do messages/index, he does def index
Continuously ask the user to enter numbers until the user enters a number that
I have a model like this class Ask(models.Model): name = models.CharField(max_length=500) designation = models.CharField(max_length=200,
The code x = 3 def f(): exec(x = 2) print(x) f() runs on
Write a Python program that will ask the user to enter a string of

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.