1
name1= input("What the first persons name")
name2=input("What is the second persons name")
name3=input("What third persons name")
hours_worked1=input("How many hours did the first person work")
hours_worked2=input("How many hours did the second person work")
hours_worked3=input("How many hours did the third person  work")

Hourly_rate_1=input("What is the first persons rate")
Hourly_rate_2=input("What is the second persons rate")
Hourly_rate_3=input("What is the third persons rate")

  print('\nname\t\tHours\trate\r')
  print(f'{name1}:\t{hours_worked1:>11}\t{Hourly_rate_1:>6}')
  print(f'{name2}:\t{hours_worked2:>11}\t{Hourly_rate_2:>6}')
  print(f'{name3}:\t{hours_worked3:>11}\t{Hourly_rate_3:>6}')

I would like to know how to bold my heading and underline them. I would also like to know how to add color to my currency.

  • can you show me in my code how to add bold and the other things i am very confused. plz help! – Kevin Mulach Apr 06 '20 at 17:38
  • Does this answer your question? [How do I print bold text in Python?](https://stackoverflow.com/questions/8924173/how-do-i-print-bold-text-in-python) – Ecliptica Apr 06 '20 at 22:25

2 Answers2

0

You can use the package termcolor to color, bold, underline text easily.

First you need to install termcolor via pip:

pip install termcolor

Here are some examples:


import sys
from termcolor import colored, cprint

text = colored('Hello, World!', 'red', attrs=['reverse', 'blink'])
print(text)
cprint('Hello, World!', 'green', 'on_red')

print_red_on_cyan = lambda x: cprint(x, 'red', 'on_cyan')
print_red_on_cyan('Hello, World!')
print_red_on_cyan('Hello, Universe!')

for i in range(10):
    cprint(i, 'magenta', end=' ')

cprint("Attention!", 'red', attrs=['bold'], file=sys.stderr)

Read the docs to get more usages.


Here is a example for your code:


from termcolor import colored

name1 = 'foo'
hours_worked1 = '2'
Hourly_rate_1 = '50'
currency = '$'

print(colored('\nname\tHours\trate\n', 'grey', attrs=['bold', 'underline']))

print(f'{colored(name1, "yellow", attrs=["bold"])}:\t'
      f'{colored(hours_worked1, "green"):>11}\t'
      f'{colored(Hourly_rate_1, "red"):>6}{colored(currency, "blue")}')

output:

enter image description here

lonsty
  • 185
  • 2
  • 10
  • so i would just add the correct syntax after my print functions and then fill my correct words i want to use? – Kevin Mulach Apr 06 '20 at 17:02
  • Yes, you need to use a specific syntax to color the text, for example, `print('\033[91mtext\033[0m')` will print `text` on red. – lonsty Apr 07 '20 at 02:27
0

I'm also new to coding. You can also change the text but I recommend the Module tkinter. Here a window pops up and shows you the result. Here is the Code:

from tkinter import * #imports tkinter
window = Tk() #creates a window
canvas = Canvas(window, height = 500, width = 500) #creates a canvas. You can change height and width values
canvas.pack()
name1= input("What the first persons name")
name2=input("What is the second persons name")
name3=input("What third persons name")

hours_worked1=input("How many hours did the first person work")
hours_worked2=input("How many hours did the second person work")
hours_worked3=input("How many hours did the third person  work")

Hourly_rate_1=input("What is the first persons rate")
Hourly_rate_2=input("What is the second persons rate")
Hourly_rate_3=input("What is the third persons rate")


canvas.create_text(200, 200, text = 'name\tHours\trate\r', fill = 'green', font = "bold 13 underline") #creates text with fill color green, bold 13 times and underlined(You can increase the number 13 to make it bolder or change the color)
canvas.create_text(200, 230, text = f'{name1}:\t{hours_worked1:>11}\t\t{Hourly_rate_1:>6}') #creates text
canvas.create_text(200, 260, text = f'{name2}:\t{hours_worked2:>11}\t\t{Hourly_rate_2:>6}') #creates text
canvas.create_text(200, 290, text = f'{name3}:\t{hours_worked3:>11}\t\t{Hourly_rate_3:>6}') #creates text
window.attributes('-topmost', 1) #brings the window to the front layer

regards, Tanmay

math scat
  • 310
  • 8
  • 17