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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:35:58+00:00 2026-05-27T07:35:58+00:00

I was writing this code in C++ and it kept giving me an answer

  • 0

I was writing this code in C++ and it kept giving me an answer that I didn’t want so I thought I should write it in python, so when I did it gave me the error “* ‘return’ outside function ([Place on hard drive], line 7)”. I searched it and found that it was to do with indentions, so I re-wrote that line of code but I still get this error. Also the program it’s self is most likely wrong and I’m not asking for you to fix that but in theory it should work, also it is to convert decimal to binary as a number. Thanks in advance :).

Here’s the code:

class gimmeANumber():
    while True:
        Number = raw_input("Please can you input a number from 0 to 255\n")
        if Number < 0 or 255 < number:
            print "Please enter a valid number\n"
        else:
            return Number

class decToBinary():
    Binary_Converter = 128
    i = 0
    Binary = 0
    while True:
        Number = gimmeANumber()
        ONumber = Number
        while (true):
            if (Number - Binary_Converter) >= 0:
                Number =- Binary_Converter
                Binary_Converter /= 2
                Binary += 10**7-i
            else:
                Binary_Converter /= 2
            i += 1
            if i == 8:
                break
    print "\nThe origanal number was " + str(ONumber) + " Now it is " + str(Binary) + " in Binary.\n"
  • 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-27T07:35:59+00:00Added an answer on May 27, 2026 at 7:35 am

    You are telling Python that you are defining a class, because of the “class” keyword.

    However, you instead should be defining a function, using “def”.

    There are a few other things you will need to fix to make this work. For example, gimmeANumber() should return a number, but it currently returns a string. The function should look like:

    def gimmeANumber():
        while True:
            Number = raw_input("Please can you input a number from 0 to 255\n")
            Number = int(Number)
            if Number < 0 or 255 < Number:
                print "Please enter a valid number\n"
            else:
                return Number
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are the points that should be kept in mind while writing code that
I'm writing code that looks similar to this: public IEnumerable<T> Unfold<T>(this T seed) {
I am writing code that catches this OutOfMemoryException and throws a new, more intuitive
I want to fill dropdownlist which is inside FormView. I'm writing this code at
I find myself writing code that looks like this a lot: set<int> affected_items; while
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
I'm writing code like this, doing a little quick and dirty timing: var sw
I frequently find myself writing code like this: List<int> list = new List<int> {
I always find myself writing code like this: my $var = $result[0]; my $var_changed
Why does everyone tell me writing code like this is a bad practice? if

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.