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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:57:20+00:00 2026-06-13T02:57:20+00:00

Probably my coding isn’t so good and some lines wouldn’t make much sense or

  • 0

Probably my coding isn’t so good and some lines wouldn’t make much sense or are not necessary, but the code purpose is dead-simple:

I want to create a function that uses an input(string), and convert it as an integer, which is going to be use in a math problem.
Plus: I want my code to interpret a random generated number and print it as its string equivalent:

### 'one' --> 1
### 'zero' --> 0 

import random

##'one' == 1
##'zero' == 0

def name_to_number(name):
    if name == 'one':
        return 1

def number_to_name(comp_number):
    if comp_number == 1:
        return 'one'

def lit_for_num(name):
    '''(str) -> str'''

    comp_number = random.randrange(0,1)
    equation = (abs(comp_number - int(name)))
    if equation == 0:
        print('Hallo!')
        return 'Computer draws' + comp_number
    else:
        return 'Computer draws 0'

Any help is very much thanked.

  • 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-13T02:57:21+00:00Added an answer on June 13, 2026 at 2:57 am

    The first problem is that you seem to be using one as input, and hence
    int('one') will give you that error.

    Secondly, in:

    comp_number = random.randrange(0,1)
    ...
    if equation == 0:
        print('Hallo!')
        return 'Computer draws' + comp_number
    else:
        return 'Computer draws 0'
    

    the else clause will always be called because comp_number is always 0.

    rand.randrange is similar to choice(range(start, stop, step)), which means randrange(0,1) will always return 0. You would want randrange(0,2) instead if you want to either 0 or 1. Or, use random.randint(0,1) instead, which will include end points 0 and 1.

    As a bonus, to process text number to number, you may want to consider text2num written by Greg Hewgill.

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

Sidebar

Related Questions

It probably won't matter for my current utility, but just for good coding practice,
I was coding an usual jquery+AJAX code, but it isn't working and i really
Probably something really simple, but I'm having some real trouble with it. I have
Probably right in front of me, but I am not sure how to set
Probably not. But still would be nice to have it. Kinda hard to believe
This has probably been asked a million times, but I'm not getting anywhere from
i'm digging more and more into Zend_Framework, but finding good resources isn't all too
I need help with a loop... it's probably simple but I'm having difficulty coding
After a marathon coding session, where I added too much code without keeping track
Probably I'm just too dump for googling, but I always thought char arrays get

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.