hi , I have my python code but I couldn't solve it.

here my sample loop:

import os
import sys

whileloop = True

while(whileloop):
    initial_drive = "C:\\"
    inputline = input(initial_drive)                    <<< PROBLEM...
    if inputline == "exit":
        whileloop = False
    elif inputline == "about":
        print("no input")
    elif inputline == "":
        print("write a command and press enter.")
    elif inputline == "d:\\":
        initial_drive = "D:\\"
    else:
        print("bad command")

it isn't changed into "D:\\" please help me .......
---------------------------------------------------------------
=[cryptacker]=

You have to enter "d:\" to make it equal to "d:\\" since backslash is the escape character. Why not make it simple and test for "D:" only. I've added some print statements to clarify.

#!/usr/bin/python3
import os
import sys

whileloop = True

while(whileloop):
    initial_drive = "C:\\"
    inputline = input(initial_drive)
    print("inputline = %s" % (inputline))
    if inputline == "exit":
        whileloop = False
    elif inputline == "about":
        print("no input")
    elif inputline == "":
        print("write a command and press enter.")
    elif inputline in ["d:\\", "d:"]:  ## enter either "d:\" or "d:"
        initial_drive = "D:\\"
        print("initial_drive is now %s" % (initial_drive))
    else:
        print("bad command")

Edited 6 Years Ago by woooee: n/a

Okay, I am on a linux system and so I haven't worried to much about the escape characters, but I think that what you were after is getting the prompt to change from C:\\ to D:\\

What you need to do is take the initial_drive = r"C:\\" out of the while loop, because otherwise you are changing the 'initial_drive' value, but the changing it back again when the loop goes round again.

Here is the code I used to get it to work right on my system:

#!/usr/bin/python3
import os
import sys

whileloop = True
initial_drive = r"C:\\"

while(whileloop):
    inputline = raw_input(initial_drive)
    print("inputline = %s" % (inputline))
    if inputline == "exit":
        whileloop = False
    elif inputline == "about":
        print("no input")
    elif inputline == "":
        print("write a command and press enter.")
    elif inputline[0] == 'd':
        initial_drive = r"D:\\"
        print("initial_drive is now %s" % (initial_drive))
    else:
        print("bad command")
This question has already been answered. Start a new discussion instead.