88user 88user - 3 days ago 4
Python Question

combining a string with a variable in a variable

i'm a complete beginner and i'm kinda stuck on something. i'm trying to make something that you give a number to, it takes it and divides it in coins that have 5pts and coins that have 1pt. for example if you say i have 41pts it will give you 8 5pt coins and 1 1pt coin. for now i want to say if it's divisible by 5 then give 5pt coins and if it's not give 1pt coins. i've gotten this far

from tkinter import *
from tkinter import ttk
import tkinter as tk
def get_text():
global number
numbers = num_textbox.get()
number = int(numbers)
root = Tk()
root.title("Number Cent Divider")
num_col_mat = Label(root, text="Your number:")
num_textbox = Entry(root, bd=1)
enter_button = Button(root, text="Enter", command=add_text)
def popup():
popup = tk.TopLevel()
answer = Label(popup, text=answer)
B1 = ttk.Button(popup, text="Ok", command=popup.destroy)
if (number[-1] == 5 or number[-1] == 0):
answer = num

the code isn't complete yet and has errors probably everywhere since its not tested. however my problem here is i don't know how to put in a string after the var and put that whole thing in a var.like this?

answer = (number, "5pt coins")

if it's anything unlike this (which it probably is) i need help with it.
basically how do i combine a string with a variable in a different variable??


You can convert the number into string with built in str function then concatenate them with + operator or use string formatting like @Błotosmętek suggested

number = 10
answer = str(number) + " 5pt coins"
# '10 5pt coins'