pythonsql
name_id=input("请输入用户id: ")name_name=input("请输入用户名字: ")
if not ',' in name_id:
zz=name_id.split()
# print(name_id.split())
for i in zz:
sss=("insert into ss (id) values (\"i\",)" )
# print(sss)
if not ',' in name_name:
zzs = name_name.split()
# print(name_name.split())
for inz in zzs:
sssd = ("insert into ss (id) values (\"i\",\"inz\")")
print(sssd)
两个问题第一个问题这个for循环一共要打印4次但是我只想打印最里面的for 循环
第二个问题 最里面的for循环中的 i inz 变量 在sssd使用不了 麻烦大佬看看我的问题感谢 tengke 发表于 2022-7-14 11:43
name_id=input("请输入用户id: ")
name_name=input("请输入用户名字: ")
if not ',' in name_id:
name_id=input("请输入用户id: ")
name_name=input("请输入用户名字: ")
if not ',' in name_id:
zz=name_id.split()
# print(name_id.split())
for a in [-1,-2]:
for i in zz:
# sss=("insert into ss (id) values (",i,")" )
# print(sss)
if not ',' in name_name:
zzs = name_name.split()
# print(name_name.split())
for inz in zzs:
sssd = (f"insert into ss (id) values (",i,",",inz,")")
print(sssd)
本帖最后由 青出于蓝 于 2022-7-14 11:21 编辑
name_id=input("请输入用户id: ")
name_name=input("请输入用户名字: ")
if not ',' in name_id:
zz=name_id.split()
# print(name_id.split())
for i in zz[-1]:
sss=("insert into ss (id) values (\"i\",)" )
# print(sss)
if not ',' in name_name:
zzs = name_name.split()
# print(name_name.split())
for inz in zzs[-1]:
sssd = (f"insert into ss (id) values (\"{i}\",\"{inz}\")")
print(sssd)
第一个问题,-1索引就好
第二个问题,格式化(f) name_id=input("请输入用户id: ")
name_name=input("请输入用户名字: ")
if not ',' in name_id:
zz=name_id.split()
# print(name_id.split())
for i in zz:
# sss=("insert into ss (id) values (",i,")" )
# print(sss)
if not ',' in name_name:
zzs = name_name.split()
# print(name_name.split())
for inz in zzs[-1]:
sssd = (f"insert into ss (id) values (",i,",",inz,")")
print(sssd)
这个代码 打印的是
('insert into ss (id) values (', '1', ',', '4', ')')
('insert into ss (id) values (', '2', ',', '4', ')')
我想让他显示的是1对应的是 3 2 对应的4 不是这样的全部匹配 {:5_108:}
页:
[1]