在Python中,如何在不安装或使用其他pyperclip的情况下将输出复制到剪贴板?也许Win32或CTYPE?

问题描述

我正在一个项目上,该项目将创建一个计算器,但是该项目的一部分是将输出复制到剪贴板。需求状态:

  • 它必须自动将结果复制到操作系统

  • 剪贴板解决方案,要求用户安装任何软件,
    不被接受(如果您不确定,则表示没有Pyperclip。)

    import math
#for the math functions

def addition(x,y):
    return x + y
#function addition

def substraction(x,y):
    return x - y
#function for substraction

def multiplication(x,y):
    return x * y
#function for multiplacation

def division(x,y):
    return x / y
#function for division

def square_root(x):
    return math.sqrt(x)
#function for square root

Restart = "Y"
#variable used to restart the calculator

while Restart == "Y":
#while loop to keep the calculator looping

    print("Select Operation Number:")
    print("1 = Addition")
    print("2 = Substraction")
    print("3 = Multiplication")
    print("4 = Division")
    print("5 = Square Root (Of the First Number)")
#Statements to let the user kNow what operations are available

    operationInput = int(input("Enter Operation Number (1/2/3/4/5)"))
#operationInput is where the user will pick the operation by typing in the correlating number

    firstNumber = float(input("Enter First Number: "))
#User inputs the first number
    secondNumber = float(input("Enter Second Number: "))
#User inputs the second number

    if operationInput == 1:

        print(firstNumber,"+",secondNumber,"=",addition(firstNumber,secondNumber))
#If the input is 1 then it will add the two numbers

    elif operationInput == 2:

        print(firstNumber,"-",substraction(firstNumber,secondNumber))
#If the input is 2 then it will give you the difference of the two numbers

    elif operationInput == 3:

        print(firstNumber,"*",multiplication(firstNumber,secondNumber))
#If the input is 3 then it will multiply the two numbers

    elif operationInput == 4:

        print(firstNumber,"/",division(firstNumber,secondNumber))
#If the input is 4 then it will divide the two numbers

    elif operationInput == 5:

        print("The Square Root of ",firstNumber,"is ",square_root(firstNumber))
#If the input is 5 then it will find the square of the first number


    else:
        print("Invalid Input")
#If a character other than 1-5 is entered then this will show invalid

    Restart = input("Type Y to start over the calculator or N to stop")
#This will ask if the user wants to restart the calculator

    if Restart == "N":
        print("Thank you for using!")
#If no it will print thank you for using

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)