![]() |
First program issues with format display - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: First program issues with format display (/thread-7864.html) |
First program issues with format display - Jrvelandia - Jan-28-2018 Good evening, I am very basic at programming in python and am seeking help in finishing my first program. If possible help me with. 1.The welcome message. I want it to display as the image below 2. The end result so it is displayed continuously on one line like the image below. Thank you. **************************************** Things I've tried implicit continuation print(average_player) + (display_avg) print () #Line 34 Explicit continuation print(average_player) \ + (display_avg) #Line 34 print(average_player) + "'s average hit" + display_avg) print () #I've changed the average_player variable to only display the name or display the name and the string "'s average hit" ************************** <a href="https://ibb.co/cwA7Jb"><img src="https://thumb.ibb.co/cwA7Jb/Baseball_Team_management.jpg" alt="Baseball_Team_management" border="0"></a> <img> https://ibb.co/cwA7Jb </img> The program should display as above. Below is my source code. ------------------------------------------------------------------------------------- #!/usr/bin/env python3 import locale #display a welcome message print("===============================================================") print () print(" Baseball Team Manager") print () print("This program calculates the batting average for a player based") print () print("on the player's official number of at bats and hits.") print () print("================================================================") print () choice = "y" while choice.lower() == "y": # get input from the user player_names = str(input("Player's name:\t")) official_at_bat = int(input("Official number at bat:\t")) number_of_hits = int(input("Number of hits:\t")) average_player = str(input(player_names)+ "'s batting average is") # convert the players batting average average_hit = float( number_of_hits / official_at_bat) #Average hits display_avg = round(average_hit,3) # display the batting avrage print(average_player) print(display_avg) print () print () # see if the user wants to continue choice = input("continue? ( y/n): ") print () print("Bye!") ---------------------------------------------------------------------------------- RE: First program issues with format display - Jrvelandia - Jan-28-2018 #!/usr/bin/env python3 import locale #display a welcome message print("===============================================================") print () print(" Baseball Team Manager") print () print("This program calculates the batting average for a player based") print () print("on the player's official number of at bats and hits.") print () print("================================================================") print () choice = "y" while choice.lower() == "y": # get input from the user player_names = str(input("Player's name:\t")) official_at_bat = int(input("Official number at bat:\t")) number_of_hits = int(input("Number of hits:\t")) average_player = str(input(player_names)+ "'s batting average is") # convert the players batting average average_hit = float( number_of_hits / official_at_bat) #Average hits display_avg = round(average_hit,3) # display the batting avrage print(average_player) print(display_avg) print () print () # see if the user wants to continue print choice = input("continue? ( y/n): ") print () print("Bye!") RE: First program issues with format display - Larz60+ - Jan-28-2018 Try this #!/usr/bin/env python3 # import locale import os def header(): # display a welcome message os.system('cls') print("===============================================================") print() print(" Baseball Team Manager") print() print("This program calculates the batting average for a player based") print() print("on the player's official number of at bats and hits.") print() print("================================================================") print() def body(): choice = "y" while choice.lower() == "y": header() # get input from the user player_names = str(input("\nPlayer's name:\t")) official_at_bat = int(input("Official number at bat:\t")) number_of_hits = int(input("Number of hits:\t")) average_player = str(input("{}'s batting average is ".format(player_names))) # convert the players batting average average_hit = float( number_of_hits / official_at_bat) # Average hits display_avg = round(average_hit, 3) # display the batting avrage print('--------------- stats ---------------') print('Battiing Average: {}'.format(average_player)) print('Averate hitsL {}\n\n'.format(display_avg)) # see if the user wants to continue choice = input("continue? ( y/n): ") print("Bye!") body() RE: First program issues with format display - Jrvelandia - Jan-28-2018 Thank you for your replay. However, would rather the final statement match the image https://ibb.co/cwA7Jb I will try to figure it out with your code Thank you!!!! At least with your program {player_name}'s bat average is displays on the same line Larz60 (variable).format display was the solution I needed thank you. however can I get it to display two variables on the same line so the result is {players}'s is batting average is {rounded average} RE: First program issues with format display - Jrvelandia - Jan-28-2018 #!/usr/bin/env python3 #import locale import locale def header (): # display a welcome message print("===============================================================") print(" Baseball Team Manager") print () print("This program calculates the batting average for a player based") print("on the player's official number of at bats and hits.") print () print("================================================================") def body(): choice = "y" while choice.lower() == "y": header() #get input from the user print() player_names = str(input("Player's name:\t")) official_at_bat = int(input("Official number at bat:\t")) number_of_hits = int(input("Number of hits:\t")) #convert the players batting average average_hit = float( number_of_hits / official_at_bat) #average hits display_avg = round(average_hit,3) #display bat average print() print(format(player_names) + "'s batting average is " + format(display_avg)) print() #see if the user wants to continue choice = input("continue? ( y/n): ") print("Bye!")This is the final result. Thank you for your help! |