I have this code, kerbin() works perfectly, but mun() gives me a "TypeError: unsupported operand type(s) for /: 'tuple' and 'float'" error in line 62 and I don't know what can I do. Can someone help me?

#                             ___ ___                           
#   __ _ _ __   _____   ____ _| |/ _ \                          
#  / _` | '_ \ / _ \ \ / / _` | | (_) |                         
# | (_| | | | |  __/\ V / (_| | |\__, |                         
#  \__, |_| |_|\___| \_/_\__,_|_| _/_/                          
#  |___/            / ___|  ___  / _| |___      ____ _ _ __ ___ 
#                   \___ \ / _ \| |_| __\ \ /\ / / _` | '__/ _ \
#                    ___) | (_) |  _| |_ \ V  V / (_| | | |  __/
#                   |____/ \___/|_|  \__| \_/\_/ \__,_|_|  \___|
                                                                                                             

import sys

sys.stdout.write('\033c')
print("Welcome to Orbit Velocity Calculator For Kerbal Space Program")
print("Put 'help' on planet to see all the planets avaliable")
print()








##################### PLANETAS #####################


KerbinP = 3.53171639 * 10 ** 12
KerbinR = 600000

MunP = 6,5138398 * 10 ** 10
MunR = 200000







def init():
    planet = input("Put here the planet you want to orbit: ")

    sys.stdout.write('\033c')
    altitude = int(input("Put here the altitude for de orbit (km): "))



    def kerbin():
        KerbinR2 = 0
        KerbinR2 = KerbinR + altitude * 1000
        KerbinResult = KerbinP / KerbinR2
        velocity = float(KerbinResult ** 0.5)
        sys.stdout.write('\033c')
        print(f"The velocity to orbit {planet} at {altitude:.0f}km is {velocity:.0f}m/s")


        
    def mun():
        MunR2 = 0
        MunR2 = MunR + altitude * 1000
        MunResult = MunP / MunR2
        velocity = float(MunResult ** 0.5)
        sys.stdout.write('\033c')
        print(f"The velocity to orbit {planet} at {altitude:.0f}km is {velocity:.0f}m/s")
        










    def help():
        print("Kerbin, Mun, Minmus")
        init()




    if planet == "help":
        help()

    elif planet == "Kerbin":
        kerbin()

    elif planet == "Mun":
        mun()

    
    
    sys.exit()


    
init()


The problem is the comma in the statement above. It should be a .
The code currently interprets MunP to be a tuple of two numbers (6 , 5138398 * 10 ** 10), but what you wanted is MunP to just be a scalar.

The statement should read:
MunP = 6.5138398 * 10 ** 10

I hope this helps

1 Like

Hullo, I’m Scott CAMly here, with an important reminder to always… Check yo’ punctuating!

And as always, Py safe.

1 Like

This was probably not an accidental typo. Many world cultures expect to use the comma as a decimal point and the period as a thousands separator. However, Python syntax (like that of most other programming languages) does not work that way. You can configure it to output/display values that way (or read them from data in that format), but the source code uses a period as a decimal point. In many programming languages, no thousands separator is permitted when writing numbers; recent versions of Python (since 3.6) allow using an underscore as an arbitrary digit separator. But programming languages generally could not be designed to use commas this way, because they already have a different meaning.

Right, I’d assumed this was the case (thus the “check yo punctuating” remark)…decimal comma considered harmful. The fundamental issue with the decimal comma (and also the comma thousands separator, though a smaller impact in practice), is that it is syntactically and visually ambiguous with many other common uses of the comma due to its shared use to separate items, particularly in a programming context (in Python lists, sets, tuples, collections, arguments, and elsewhere, as well as in formats like CSV), whereas the decimal point lacks the same ambiguity.

I also avoid the comma thousands separator for the same reason (in writing generally, not just in programming), preferring the either the ISO-standard space, or no separator for shorter numbers.

Indeed; in fact, in a historical quirk, Python uses the decimal comma by default when outputting timestamps from the logging module, despite using a decimal point almost everywhere else, and needs a fair bit of work to override that. This creates a quite unfortunate ambiguity, as to a many viewers might naturally assume the value after the comma is another data field in the logging schema (including myself; for the while when I saw logging messages from other Python applications I thought it was a line number of some sort), as something similar is used in the output of other tools like linters. By contrast, the decimal point lacks the same ambiguity, at least in that context, and is consistent with usage in the Python language and almost everywhere else in Python’s default output.

How hard can computer science be!?

Got it, thanks you very much! :smiley:

Almost certainly, 6.5138398e10 is the way to write it in Python.