pythoninput函数在运行时检测venv路径

问题描述

我有以下代码

main.py

import arithmetic_mean as am

grades = [int(x) for x in input("Enter your math,physics,and chem scores: ").split()]

score = am.arith_mean(grades)

if score>=90:
    print("\nYour grade is %.2f and you passed with an A."%score)
elif 80<=score<90:
    print("\nYour grade is %.2f and you passed with a B."%score)
elif 70<=score<80:
    print("\nYour grade is %.2f and you passed with a C."%score)
elif 60<=score<70:
    print("\nYour grade is %.2f and you passed with a D."%score)
else:
    print("\nYour grade is %.2f and you Failed with an F. That sounds weird. FFFFFFF"%score) 

arithmetic_mean.py

def arith_mean(lst):
    num_sum = 0
    length = len(lst)
    for i in lst:
        num_sum += i
    return num_sum / length

我正在带代码运行程序的VS代码中的集成终端中运行main。我正在使用内置的虚拟环境工具。在开始编码或运行文件之前,我先使用VS代码在git bash集成外壳中启动虚拟环境,

. .venv/scripts/activate

在这是我遇到的问题。当我第一次尝试运行main时,我得到以下信息:

$ python -u "c:\Users\{User}\Documents\PROGRAMMING\Python\udemy_course\program_e
xamples\grading_application.py"
Enter your math,and chem scores: source c:/Users/{User}/Documents/PROGRAMMING/Python/udemy_course/.venv/Scripts/activate
Traceback (most recent call last):
  File "c:\Users\{User}\Documents\PROGRAMMING\Python\udemy_course\program_examples\grading_application.py",line 25,in <module>
    grades = [int(x) for x in input("Enter your math,and chem scores: ").split()]
  File "c:\Users\{User}\Documents\PROGRAMMING\Python\udemy_course\program_examples\grading_application.py",in <listcomp>
    grades = [int(x) for x in input("Enter your math,and chem scores: ").split()]
ValueError: invalid literal for int() with base 10: 'source'

但是在此初始时间之后运行该应用程序,它可以正常工作且没有错误,并且输入功能可以按预期运行在主函数中。

有什么作用?好像虚拟环境启动发生在我最初输入的地方一样。好像是在错误的时间或某些时间发生的,但我不知道。

我还知道我的代码可能不遵循python专家使用的语法惯例以及其他不良做法,因此,如果您发现任何问题,我将永远感激您的建设性批评。抱歉,我并不是python的专家。任何建议都欢迎。谢谢。

解决方法

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

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...