设变量,a, list1 = [80,60,70,90,100,68,99,-1] list2 = [] 用for循环和while循环 满足从列表1当中逐一取元素放到列表2中去,碰到-1跳出循环即可 for循环和while循环
时间: 2023-10-03 11:10:36 浏览: 31
# for循环
list1 = [80,60,70,90,100,68,99,-1]
list2 = []
for num in list1:
if num == -1:
break
list2.append(num)
print(list2)
# while循环
list1 = [80,60,70,90,100,68,99,-1]
list2 = []
i = 0
while i < len(list1):
if list1[i] == -1:
break
list2.append(list1[i])
i += 1
print(list2)
相关问题
设变量,a, list1 = [80,60,70,90,100,68,99,-1] list2 = [] 满足从列表1当中逐一取元素放到列表2中去,碰到-1跳出循环即可 用for循环和while循环写
# for循环写法
a = 0
list1 = [80,60,70,90,100,68,99,-1]
list2 = []
for i in list1:
if i == -1:
break
list2.append(i)
print(list2)
# while循环写法
a = 0
list1 = [80,60,70,90,100,68,99,-1]
list2 = []
while list1[a] != -1:
list2.append(list1[a])
a += 1
print(list2)
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb arm net.c
这段引用内容是一个关于编译和运行一个小程序的示例。根据引用内容,这个程序使用了Redis的C语言客户端库hiredis。在编译过程中,可能会遇到找不到libhiredis.so.0.13的问题。为了解决这个问题,可以设置gcc编译器的头文件查找路径,将Redis的include目录添加到C_INCLUDE_PATH环境变量中。然后重新编译并运行程序,应该就可以成功了。
#### 引用[.reference_title]
- *1* *2* *3* [安装Redis-4.0.1以及hiredis库](https://blog.csdn.net/test1280/article/details/79533092)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文