【发布时间】:2014-10-25 02:13:37
【问题描述】:
以下问题是家庭作业(我将首先列出问题,然后是我的编码)...期待您的来信。
问题: 设计一个具有两个并行数组的程序:一个名为 people 的字符串数组,它用你的 7 个朋友的名字初始化,一个名为 phone numbers 的字符串数组,用你朋友的电话号码初始化。该程序应允许用户输入人名(或人名的一部分)。然后它应该在 people 数组中搜索那个人。如果找到该人,它应该从电话号码数组中获取该人的电话号码并显示它。如果在 people 数组中没有找到该人,则程序应显示一条消息指示。
代码:
Def main:
#declare variables
Size=7
People=[any 7 common names]
Phonenumbers= [7 phone numbers]
Searchvalue = 0
index = 0
Found = false
Inputpeople = 0
Found =false
#get name from user
InputpeopleInputpeople = raw_input("Enter name you are looking for:"
While found ==false and index >= size-1
If (people[index])== phonenumbers[index]:
Found == true
Else:
Index = index +1
If found ==1:
Print"the phone number is ",phonenumbers
Else:
Print"there is no listing for this number"
主要()
【问题讨论】:
-
您必须使用正确的语法编辑您的问题。没有办法接受大写的关键字。另外,你的问题是什么?
-
不要大写
if、else、while或print。大小写对变量也很重要,例如Index不与index相同。 -
大小、人物和电话号码大写,其余小写
-
你有什么问题?
-
考虑到这是一种学习情况,对你来说,先找到并修复所有语法错误,然后再处理算法,对你很有指导意义。