【发布时间】:2023-02-16 20:47:55
【问题描述】:
我刚开始使用 Python3 中的 main() 部分。如果您能提供任何帮助,我将不胜感激。
抛出的错误:
python3 Artificial_snake_anti_venom.py
File "Artificial_snake_anti_venom.py", line 67
def main(): snake_families = get_all_snake_families() all_antivenoms = create_all_antivenoms(snake_families) save_antivenoms_file(all_antivenoms.txt) show_user_message() if __name__ == "__main__":
^
SyntaxError: invalid syntax
代码:
#!/usr/bin/python
# Creating Synthetic Snake Antivenom
import random
# Create a function that can generate antivenom serum from snake venom
def make_antivenom(snake_venom):
# Create a loop that can iterate through the snake venom and be used to create the antivenom
antivenom_serum = []
for element in snake_venom:
# Create a sample of each element in the snake venom
sample = random.sample(element, len(element))
# Append each sample to a serum stored in the list
antivenom_serum.append(sample)
# Return the complete antivenom serum once all samples have been appended
return antivenom_serum
# Call the function
antivenom_serum = make_antivenom()
def make_antivenom():
antivenom_serum = []
# Append polyvalent antivenom
polyvalent_serum = create_polyvalent_antivenom()
antivenom_serum.append(polyvalent_serum)
# Append a range of species specific antivenom
for snake_species in get_all_snake_species():
species_specific_serum = create_species_specific_antivenom(snake_species)
antivenom_serum.append(species_specific_serum)
# Append a range of polyspecific antivenom
for snake_family in get_all_snake_families():
polyspecific_serum = create_polyspecific_antivenom(snake_family)
antivenom_serum.append(polyspecific_serum)
return antivenom_serum
# Create a polyvalent antivenom serum
def create_polyvalent_antivenom():
# code to create polyvalent antivenom
# Create a species specific antivenom serum
def create_species_specific_antivenom(snake_species):
# code to create species specific antivenom
# Create a polyspecific antivenom serum
def create_polyspecific_antivenom(snake_family):
# code to create polyspcecific antivenom
# Get a list of all snake species
def get_all_snake_species():
# code to get all snake species
# Get a list of all snake families
def get_all_snake_families():
# code to get list of all snake families here
pass
# Create dictionary with all antivenoms for snake species
def create_all_antivenoms(): # code to generate antivenoms based on snake families pass # Loop over created antivenoms and save to file
def save_antivenoms_file(): # loop over antivenom dict and save to file
pass
# Display message to user
def show_user_message(): print("All snake antivenoms have been generated!")
# Call main function
def main(): snake_families = get_all_snake_families() all_antivenoms = create_all_antivenoms(snake_families) save_antivenoms_file(all_antivenoms.txt) show_user_message() if __name__ == "__main__":
main()
谢谢你的时间。 杰。 汤森原子公司。
到目前为止我做了什么。
- 检查了空格。
- 将 main() 移至新行。
- 尝试将 all_antivenoms 更改为带引号和不带引号的所有 antivenoms.txt。
它在正确的目录中;一直是chmod +x。
所有的结果都是一样的。
python3 Artificial_snake_anti_venom.py
File "Artificial_snake_anti_venom.py", line 67
def main(): snake_families = get_all_snake_families() all_antivenoms = create_all_antivenoms(snake_families) save_antivenoms_file(all_antivenoms.txt) show_user_message() if __name__ == "__main__":
^
SyntaxError: invalid syntax
【问题讨论】: