I have previously used this StackOverflow question to write the following code to my program:
import os
os.system('mode con: cols=20 lines=5')
When I double click this Python script from File Explorer, this used to open the console window (command window I believe) in the specified size. However, since recently, it is not doing that anymore. Instead, it now opens Windows PowerShell, and the resizing doesn't function.
My desired result is to resize the window that my print statements are printed to. Also, I should be able to resize the window after making some new print statements. For full code, see below. If I should reduce the code for readability, please let me know.
import os
import math
import sys
# defining round_half_up
def round_half_up(n, decimals=0):
multiplier = 10 ** decimals
return math.floor(n * multiplier + 0.5) / multiplier
def main():
IDLE = "idlelib" in sys.modules
if not IDLE:
os.system('mode con: cols=20 lines=5')
while True: # get some input until it is valid
try:
points = float(input("Total points: "))
if points==int(points):
points = int(points)
break
except ValueError:
print("That's not a number.\n")
while True: # get some more input while it is valid
try:
grade = int(input("Maximum grade: "))
break
except ValueError:
print("That's not a whole number.\n")
if not IDLE:
# calculate the size of the window
cols = 5 + 4*(4+4+10) -10
lines = math.ceil(points) + 5
# apply the new size of the window
os.system('mode con: cols={:d} lines={:d}'.format(cols, lines))
# print all the results
for i in range(math.ceil(points)):
lst = [0.]*8
for j in range(4):
lst[j*2] = i+j*0.25
lst[j*2+1] = round_half_up((i+j*0.25)*grade/points, 1)
print(("{:5.2f} -->{:4.1f}{:10.2f} -->{:4.1f}{:10.2f}" + \
"-->{:4.1f}{:10.2f} -->{:4.1f}").format(*lst))
print("{:5.2f} -->{:4.1f}".format(math.ceil(points), grade))
print()
if points==int(points):
tickets = "90% is either {:.2f}/{:d} or {:.1f}/{:d}"
else:
tickets = "90% is either {:.2f}/{:.1f} or {:.1f}/{:d}"
print(tickets.format(0.9*points, points, 0.9*grade, grade))
print()
if __name__=='__main__':
while True: # keep window open and/or get new inputs until enter is pressed
main()
again = input("Type anything to start again, or just press enter to close:")
if again == "":
break