كيف يمكنني حذف العنصر رقم 2-3 من السطر الأول؟
line_1= [“” ,“”, “”]
كيف يمكنني حذف العنصر رقم 2-3 من السطر الأول؟
line_1= [“” ,“”, “”]
line_1.remove(1,"🌿")
print(line_1)
ine_1.remove(1,"🌿")
~~~~~~~~~~~~~^^^^^^^^
TypeError: list.remove() takes exactly one argument (2 given)
المفروض تعطى remove شيء واحد وليس شيئين
هذا كود المشروع، أنا لم أرَ الحل بعد الكود يعمل، لكن أعتقد أنه أطول بكثير.
```print("welcome to place the rabbit 🐰. ")
line_1= ["🌿","🌿","🌿"]
line_2= ["🌿","🌿","🌿"]
line_3= ["🌿","🌿","🌿"]
print(line_1)
print(line_2)
print(line_3)
print("Where should the rabbit go 🐇?")
choice= input("Please chose a row and a column:")
#=============================================
if choice == "11":
line_1.insert(0,"🐇")
line_1.remove("🌿")
print(line_1)
print(line_2)
print(line_3)
elif choice == "12":
line_1.insert(1,"🐇")
#line_1.remove ()
print(line_1)
print(line_2)
print(line_3)
elif choice == "13":
line_1.append("🐇")
line_1.remove ("🌿")
print(line_1)
print(line_2)
print(line_3)
elif choice == "21":
line_2.insert(0,"🐇")
line_2.remove("🌿")
print(line_1)
print(line_2)
print(line_3)
elif choice== "22" :
line_2.insert(1,"🐇")
line_2.remove,("2")
print(line_1)
print(line_2)
print(line_3)
elif choice == "23":
line_2.append("🐇")
line_2.remove("🌿")
print(line_1)
print(line_2)
print(line_3)
elif choice== "31":
line_3.insert(0,"🐇")
line_3.remove("🌿")
print(line_1)
print(line_2)
print(line_3)
elif choice == "32":
line_3.insert(1,"🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice == "33":
line_3.append("🐇")
line_3.remove ("🌿")
print(line_1)
print(line_2)
print(line_3)
عدلت اشياء بسيطه وصار شغال
هذا هو الكود بعد التصحيح :
print("welcome to place the rabbit 🐰. ")
line_1= ["🌿","🌿","🌿"]
line_2= ["🌿","🌿","🌿"]
line_3= ["🌿","🌿","🌿"]
print(line_1)
print(line_2)
print(line_3)
print("Where should the rabbit go 🐇?")
choice= input("Please chose a row and a column:")
#=============================================
if choice == "11":
line_1.remove ("🌿")
line_1.insert(0,"🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice == "12":
line_1.remove ("🌿")
line_1.insert(1,"🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice == "13":
line_1.remove ("🌿")
line_1.append("🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice == "21":
line_2.remove ("🌿")
line_2.insert(0,"🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice== "22" :
line_2.remove ("🌿")
line_2.insert(1,"🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice == "23":
line_2.remove ("🌿")
line_2.append("🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice== "31":
line_3.remove ("🌿")
line_3.insert(0,"🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice == "32":
line_3.remove ("🌿")
line_3.insert(1,"🐇")
print(line_1)
print(line_2)
print(line_3)
elif choice == "33":
line_3.remove ("🌿")
line_3.append("🐇")
print(line_1)
print(line_2)
print(line_3)
في الاثنين، ٦ يناير، ٢٠٢٥ ١٢:١٥ م Otman عبر أكتو كود تعلم البرمجة من الصفر <notifications@octucode1.discoursemail.com> كتب:
آه، فهمت أنه يجب أن أضع remove قبل insert. أنت معلم، شكرًا.
عـفـوا اخـي الـكريـم
ها هو المشروع =»
**area=[[“”,“”,“”],
[“”,“”,“”],
[“”,“”,“”]]
ans=input(f"{area[0]}\n {area[1]} \n {area[2]}\n Write place the rabbit \n Put height and width. ")
ans1=int(len(ans))
if ans1==2:
area[int(ans[0])-1]. remove (“”)
area[int(ans[0])-1].insert(int(ans[1])-1,“”)
print(f"{area[0]}\n{area[1]}\n{area[2]}")
else:
print(“Put the two places just.”)**
جميل وهذا نفس الكود ولاكن بطريقه منظمه حتى يسهل نسخه :
area=[["🌿","🌿","🌿"],
["🌿","🌿","🌿"],
["🌿","🌿","🌿"]]
ans=input(f"{area[0]}\n{area[1]}\n {area[2]}\nWrite place the rabbit 🐇 \n Put height and width. ")
ans1=int(len(ans))
if ans1==2:
area[int(ans[0])-1]. remove ("🌿")
area[int(ans[0])-1].insert(int(ans[1])-1,"🐇")
print(f"{area[0]}\n{area[1]}\n{area[2]}")
else:
print("Put the two places just.")
مكنتش عارف أرسله كده الصراحة ،
شكرًا .
هههه إنصدمت من الحل ههههه انا عامل الكود من 70 سطر والمستر 10 سطور فقط
ههه ، عادى في المشاريع الصغيره ولاكن في المشاريع الكبيره لازم تحاول تقلل عدد السطور عشان تقلل مساحه التخزين للعبه وتقلل الجليتشات، والمهم حاليا انك عرفت توصل للحل
كويس انك حاولت وطلعت بحل, انا مكنتش عارف احله ازاي اصلا هههههه
شكراااا على كلامك المشجع
print("Welcome to the place Rabbit.")
area=[ ["🌿","🌿","🌿"],["🌿","🌿","🌿"],["🌿","🌿","🌿"] ]
print (f"{area[0]}\n{area[1]} \n{area[2]} \n{"where should the rabbit go?🐇"} ")
all= (input("please chose hight and length :"))
hight= int(all[0])
length= int (all[1])
area [hight-1][length-1] = "🐇"
print(f"{area[0]}\n {area[1]}\n {area[2]}")