gpt4 book ai didi

python - 格式化整数输出时遇到问题

转载 作者:太空宇宙 更新时间:2023-11-03 20:40:38 25 4
gpt4 key购买 nike

我正在制作一个包含设计和所有内容的标记表,我已经完成了在字符串上使用格式设置的所有操作,一切都很好,但我在 3 个地方遇到了问题,下面是我的代码,在代码之后我还将给出结果,这样你就可以看到我在哪里遇到问题。问题出在分数和总计上。

        from datetime import datetime
year=datetime.now().year
date=datetime.now().strftime("%d-%m-%Y")
while True:
while True:
Name=input("\nType your name:")
if len(Name)==0:
print('''"You made mistake while filling name section"''')
else:
break
while True:
F_Name=input("\nType father name:")
if len(F_Name)==0:
print('''"You made mistake while filling f.name section"''')
else:
break
while True:
School=input("\nType your school name:")
if len(School)==0:
print('''"You made mistake while filling school section"''')
else:
break
while True:
Group=input("\nType your group eg.Science,Arts:")
if len(Group)==0:
print('''"You made mistake while filling group section"''')
else:
break
while True:
Board=input("\nType name of your board:")
if len(Board)==0:
print('''"You made mistake while filling board section"''')
else:
break
while True:
try:
num1 = int(input('\nEnter number of total subjects:'))
except ValueError:
print('''\n"Please enter only number"''')
else:
break
l_Subjects=[]
l_T_Marks=[]
l_Marks=[]
S_numbers=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelth","thirteenth","fourteenth","fifteenth","sixteenth","eighteenth","nineteenth","twentieth"]
for i in range(num1):
print(f'''\n"For the {S_numbers.pop(0)} subject"\n''')
Subjects=input("Type subject name:")
l_Subjects.append(Subjects)
while True:
try:
T_Marks= int(input(f'Enter total marks for {Subjects}:'))
l_T_Marks.append(T_Marks)
while True:
try:
Marks = int(input('Enter obtained marks:'))

except ValueError:
print('''\n"Please enter only number"''')
if Marks>T_Marks:
print('''\n"Please insert correct marks"''')
else:
l_Marks.append(Marks)
break
except ValueError:
print('''\n"Please enter only number"''')
else:
break
print('''\n\n "Here is your Marksheet"\n\n''')
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print(f"§ {Board.title(): <54}§")
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print(f"§ Examination Annual {year: <51}§")
print(f"{'§': <80}§")
print(f"§ Name {Name.title(): <58}§")
print(f"{'§': <80}§")
print(f"§ F.Name {F_Name.title(): <58}§")
print(f"{'§': <80}§")
print(f"§ School/Private {School.title(): <58}§")
print(f"{'§': <80}§")
print(f"§ Group {Group.title(): <58}§")
print(f"{'§': <80}§")
print("§ _________________________________________________________________________ §")
print("§ | | §")
print("§ | Subjects | §")
print("§ |_________________________________________________________________________| §")
print("§ | Component | Marks | §")
print("§ |__________________________________|______________________________________| §")
l_T_Marks1=list(l_T_Marks)
l_Marks1=l_Marks.copy()
l_Subjects1=l_Subjects.copy()
for i in list(l_Marks):
print(f"§ | {l_Subjects.pop(0): <22}| {l_Marks.pop(0)}/{l_T_Marks.pop(0): <17}| §")
print(f"§ |__________________________________|______________________________________| §")
Sum_Marks=(sum(l_Marks1))
Sum_T_Marks=(sum(l_T_Marks1))
Percentage=(Sum_Marks/Sum_T_Marks)*100
if(Percentage>=80):
Grade='A+'
elif(Percentage>=70 and Percentage<80):
Grade='A'
elif(Percentage>=60 and Percentage<70):
Grade='B'
elif(Percentage>=50 and Percentage<60):
Grade='C'
elif(Percentage>=40 and Percentage<50):
Grade='D'
else:
Failed=('''"Sorry! You have failed the exam." §''')
Grade='F'
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print(f"§ Grand Total {Sum_Marks} out of {Sum_T_Marks:<25}§")
print(f"{'§': <80}§")
print("§ _______ §")
print("§ | | §")
print(f"§ Grade | {Grade.title(): <4}| §")
print("§ |_______| §")
if Grade=='F':
print(f"{'§': <80}§")
print(f"§ {Failed: <5}")
print(f"{'§': <80}§")
print("§ Waseem Munir §")
print("§ _________________________ §")
print("§ Controller of Examination §")
print(f"{'§': <80}§")
print(f"§ Dated:{date: <72}§")
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
while True:
Repeat=input("\nDo you want to repeat?\n\nYes or No:")
Repeat=Repeat.lower()
if Repeat not in ["yes","y","no","n"]:
print('''"\nPlease select correct option"''')
else:
break
if Repeat in ["yes","y"]:
continue
else:
if Repeat in ["no","n"]:
print("\n-----Thank you for using-----")
input()
break

这是输出。

                                    "Here is your Marksheet"


<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
§ §
§ §
§ Bermingham Board §
§ §
§ §
§ Examination Annual 2019 §
§ §
§ Name John Michael §
§ §
§ F.Name Brad Michael §
§ §
§ School/Private Bermingham High School §
§ §
§ Group Science §
§ §
§ _________________________________________________________________________ §
§ | | §
§ | Subjects | §
§ |_________________________________________________________________________| §
§ | Component | Marks | §
§ |__________________________________|______________________________________| §
§ | Maths | 76/100 | §
§ |__________________________________|______________________________________| §
§ | English | 81/100 | §
§ |__________________________________|______________________________________| §
§ §
§ §
§ Grand Total 157 out of 200 §
§ §
§ _______ §
§ | | §
§ Grade | A | §
§ |_______| §
§ §
§ Waseem Munir §
§ _________________________ §
§ Controller of Examination §
§ §
§ Dated:04-07-2019 §
§ §
§ §
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Do you want to repeat?

Yes or No:

最佳答案

您必须在整数输出中遇到问题的所有 3 个位置使用字符,您需要更改 {Sum_T_Marks:<25} 中的总计 {Sum_Marks:>3 或 4 #(根据每个输出的需要)}§ ")。我已更正下面的代码。

        from datetime import datetime
year=datetime.now().year
date=datetime.now().strftime("%d-%m-%Y")
while True:
while True:
Name=input("\nType your name:")
if len(Name)==0:
print('''"You made mistake while filling name section"''')
else:
break
while True:
F_Name=input("\nType father name:")
if len(F_Name)==0:
print('''"You made mistake while filling f.name section"''')
else:
break
while True:
School=input("\nType your school name:")
if len(School)==0:
print('''"You made mistake while filling school section"''')
else:
break
while True:
Group=input("\nType your group eg.Science,Arts:")
if len(Group)==0:
print('''"You made mistake while filling group section"''')
else:
break
while True:
Board=input("\nType name of your board:")
if len(Board)==0:
print('''"You made mistake while filling board section"''')
else:
break
while True:
try:
num1 = int(input('\nEnter number of total subjects:'))
except ValueError:
print('''\n"Please enter only number"''')
else:
break
l_Subjects=[]
l_T_Marks=[]
l_Marks=[]
S_numbers=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelth","thirteenth","fourteenth","fifteenth","sixteenth","eighteenth","nineteenth","twentieth"]
for i in range(num1):
print(f'''\n"For the {S_numbers.pop(0)} subject"\n''')
Subjects=input("Type subject name:")
l_Subjects.append(Subjects)
while True:
try:
T_Marks= int(input(f'Enter total marks for {Subjects}:'))
l_T_Marks.append(T_Marks)
while True:
try:
Marks = int(input('Enter obtained marks:'))

except ValueError:
print('''\n"Please enter only number"''')
if Marks>T_Marks:
print('''\n"Please insert correct marks"''')
else:
l_Marks.append(Marks)
break
except ValueError:
print('''\n"Please enter only number"''')
else:
break
print('''\n\n "Here is your Marksheet"\n\n''')
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print(f"§ {Board.title(): <54}§")
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print(f"§ Examination Annual {year: <51}§")
print(f"{'§': <80}§")
print(f"§ Name {Name.title(): <58}§")
print(f"{'§': <80}§")
print(f"§ F.Name {F_Name.title(): <58}§")
print(f"{'§': <80}§")
print(f"§ School/Private {School.title(): <58}§")
print(f"{'§': <80}§")
print(f"§ Group {Group.title(): <58}§")
print(f"{'§': <80}§")
print("§ _________________________________________________________________________ §")
print("§ | | §")
print("§ | Subjects | §")
print("§ |_________________________________________________________________________| §")
print("§ | Component | Marks | §")
print("§ |__________________________________|______________________________________| §")
l_T_Marks1=list(l_T_Marks)
l_Marks1=l_Marks.copy()
l_Subjects1=l_Subjects.copy()
for i in list(l_Marks):
print(f"§ | {l_Subjects.pop(0): <22}| {l_Marks.pop(0):>4}/{l_T_Marks.pop(0): <16}| §")
print(f"§ |__________________________________|______________________________________| §")
Sum_Marks=(sum(l_Marks1))
Sum_T_Marks=(sum(l_T_Marks1))
Percentage=(Sum_Marks/Sum_T_Marks)*100
if(Percentage>=80):
Grade='A+'
elif(Percentage>=70 and Percentage<80):
Grade='A'
elif(Percentage>=60 and Percentage<70):
Grade='B'
elif(Percentage>=50 and Percentage<60):
Grade='C'
elif(Percentage>=40 and Percentage<50):
Grade='D'
else:
Failed=('''"Sorry! You have failed the exam." §''')
Grade='F'
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print(f"§ Grand Total {Sum_Marks:>4} out of {Sum_T_Marks:<23}§")
print(f"{'§': <80}§")
print("§ _______ §")
print("§ | | §")
print(f"§ Grade | {Grade.title(): <4}| §")
print("§ |_______| §")
if Grade=='F':
print(f"{'§': <80}§")
print(f"§ {Failed: <5}")
print(f"{'§': <80}§")
print("§ Waseem Munir §")
print("§ _________________________ §")
print("§ Controller of Examination §")
print(f"{'§': <80}§")
print(f"§ Dated:{date: <72}§")
print(f"{'§': <80}§")
print(f"{'§': <80}§")
print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
while True:
Repeat=input("\nDo you want to repeat?\n\nYes or No:")
Repeat=Repeat.lower()
if Repeat not in ["yes","y","no","n"]:
print('''"\nPlease select correct option"''')
else:
break
if Repeat in ["yes","y"]:
continue
else:
if Repeat in ["no","n"]:
print("\n-----Thank you for using-----")
input()
break

关于python - 格式化整数输出时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56886771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com