Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Not adding up

    Help
    2
    3
    26
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DANEEBOY
      DANEEBOY last edited by

      I am writing a program that I input the results of a dice throw and press a button and it adds all dice results together.

      Dice1 = input("Dice One Result, false")
      Dice2 = input("Dice Two Result, false")
      Dice3 = input("Dice three Result, false")
      //this is done in a function

      The press B button to add the three dice results together.

      Result = dice1+dice2+dice3
      //this is done in a different function

      Say dice1 = 2, dice2 = 5 and dice3 = 1
      As you would expect you would get a result of 8 but I'm not it gives me a result like this

      Result = 251

      I can't understand why it's doing it this way and even reading the fuze help doesn't help.
      Can somebody please help me with this?

      Thanks in advance.

      Kat 1 Reply Last reply Reply Quote 1
      • Kat
        Kat Fuze Team @DANEEBOY last edited by

        @daneeboy I believe it's treating the numbers you get from input() as strings so when you 'add' them it just sticks one after the other. You could try using int() to convert from strings, either when you first take the inputs or when you add them together, eg.

        Dice1 = int( input("Dice One Result, false") )
        or
        Result = int(dice1) + int(dice2) + int(dice3)

        DANEEBOY 1 Reply Last reply Reply Quote 0
        • DANEEBOY
          DANEEBOY @Kat last edited by

          @kat thank you I will give that a try.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post