第一次尝试运行此代码并在第21行遇到语法错误。不确定这是从哪里来的,因为我在代码之前没有做太多。
#defining the read method
def read():
#opening data from first line
pulsars = open("pulsars1.txt","r")
#opening data from second line
signals = open("signals1.txt","r")
#creating a new empty list
astro_list = []
#reading pulsar line by line/turns all of this into string
pulsar_data = pulsars.read()
#reading signal data/turns all of this into string
signal_data = signals.read()
#appending pulsar values to list
for all_pulsar_data in range(0,len(pulsar_data)):
astro_list.append(pulsar_data)
#appending signal data to list
for all_signal_data in range(0,len(signal_data)):
astro_list.append(signal_data)
return(astro_list)
#defining the main function
def main():
#displaying a descriptiong of what the program does
purpose = "This program proccess data from the Purdue Pulsar Laboratory"
underheading = "=" * len(purpose)
print(purpose)
print(underheading)
print("It reads the data from 2 files containing the pulsar name and signal strength, \nthen combines them and displays the results.")
#accepting inputs from the user about file names
pulsar_name = input("\nPulsar name file: ")
signal_strength = input("Signal strength: ")
#reading values
print("\nAnalyzing data from" , pulsar_name, "and", signal_strength, "files...")
print(" ","Reading from" ,pulsar_name,"...")
print(" ","Reading from" ,signal_strength,"...")
print(" ","Combining values...")
#displaying the top part of the table
astro_list = read()
count_head= "\n The combined BOOYA data includes", len(astro_list), "values."
print(count_head)
print("=" * len(count_head))
print(astro_list)
答案 0 :(得分:0)
如果你在PyCharm中打开这样的文件,那么错误就会变得非常明显。希望这有帮助!
# defining the read function
def read():
#opening data from first line
pulsars = open("pulsars1.txt","r")
#opening data from second line
signals = open("signals1.txt","r")
#creating a new empty list
astro_list = []
#reading pulsar line by line/turns all of this into string
pulsar_data = pulsars.read()
#reading signal data/turns all of this into string
signal_data = signals.read()
#appending pulsar values to list
for all_pulsar_data in range(0,len(pulsar_data)):
astro_list.append(pulsar_data)
#appending signal data to list
for all_signal_data in range(0,len(signal_data)):
astro_list.append(signal_data)
return(astro_list)
#defining the main function
def main():
astro_list = read()
#displaying a descriptiong of what the program does
purpose = "This program proccess data from the Purdue Pulsar Laboratory"
underheading = "=" * len(purpose)
print(purpose)
print(underheading)
print("It reads the data from 2 files containing the pulsar name and signal strength, \nthen combines them and displays the results.")
#accepting inputs from the user about file names
pulsar_name = input("\nPulsar name file: ")
signal_strength = input("Signal strength: ")
#reading values
print("\nAnalyzing data from" , pulsar_name, "and", signal_strength, "files...")
print(" ","Reading from" ,pulsar_name,"...")
print(" ","Reading from" ,signal_strength,"...")
print(" ","Combining values...")
#displaying the top part of the table
count_head= "\n The combined BOOYA data includes", len(astro_list), "values."
print(count_head)
print("=" * len(count_head))
print(astro_list)
if __name__ == '__main__':
main()
答案 1 :(得分:0)
请参阅:
for all pulsar_data in range(0, len(pulsar_data)**<-**):
astro_list.append(pulsar_data)