Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
switch case not working
#1
I am trying to read a file using a switch case and an input.




while True:
  choice = input("(1) Write A File\n(2) Read A File\n(3) Append A File\n\n")
  match choice:
    case 1:
      pass
    case 2:
      file_name = input("Enter The File Name: ")
      file_name = open(file_name, "r")
      print(file_name)
      file_name.close()
    case 3:
      pass
Reply
#2
input returns str, you try to match int
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Switch case or match case? Frankduc 9 4,540 Jan-20-2022, 01:56 PM
Last Post: Frankduc
  best way to use switch case? korenron 8 3,023 Aug-18-2021, 03:16 PM
Last Post: naughtyCat
  How do I do this? Switch Case? mstichler 4 2,594 Jun-05-2020, 10:27 AM
Last Post: snippsat
  How to use switch/case in python? newbieguy 9 4,091 Nov-08-2019, 11:35 AM
Last Post: newbieguy
  switch limitations MuntyScruntfundle 3 2,386 Jan-27-2019, 06:11 PM
Last Post: aakashjha001
  How to write switch case statement in Python pyhelp 9 9,256 Nov-11-2018, 08:53 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020