...
def Encrypt(input):
res=''
for i in input:
k = len(input) + 1
j=1
while j < k:
print("j is ",j)
val = ord(i) + j
res = res + ' ' + str(val)
j = j + 1
break
return res
input=str(input("Enter the input string:\n"))
result=Encrypt(input)
print("The encrypted value is\n",result)
While running:
Code:
Enter the input string:
well
j is 1
j is 1
j is 1
j is 1
The encrypted value is
120 102 109 109
But the output i expect is :
Code:
j is 1
j is 2
j is 3
j is 4
The encrypted value is
120 103 111 112
...
Looks like your variable "j" is being reset in every loop iteration.
If you want it incremented in every iteration, then move it outside the "for" loop - either at the beginning of the function or immediately below the assignment of "res".
def Encrypt(input):
res=''
j=1
for i in input:
k = len(input) + 1
while j < k:
print("j is ",j)
val = ord(i) + j
res = res + ' ' + str(val)
j = j + 1
return res
input=str(input("Enter the input string:\n"))
result=Encrypt(input)
print("The encrypted value is\n",result)
The result is:
Code:
Enter the input string:
well
j is 1
j is 2
j is 3
j is 4
The encrypted value is
120 121 122 123
It's not coming out from the while loop for each iteration.
Even if i use break also, i am getting the same result.,
But my expected result is :
def Encrypt(input):
res=''
j=1
for i in input:
k = len(input) + 1
while j < k:
print("j is ",j)
val = ord(i) + j
res = res + ' ' + str(val)
j = j + 1
return res
input=str(input("Enter the input string:\n"))
result=Encrypt(input)
print("The encrypted value is\n",result)
...
No, you have not. You did move the assignment statement outside the loop, but you also removed the "break" statement.
I did not mention anything about the "break" statement.
Quote:
...
Even if i use break also, i am getting the same result.,
...
def Encrypt(input):
res=''
j=1
for i in input:
k = len(input) + 1
while j < k:
print("j is ",j)
val = ord(i) + j
res = res + ' ' + str(val)
j = j + 1
break
return res
input=str(input("Enter the input string:\n"))
result=Encrypt(input)
print("The encrypted value is\n",result)
The result is:
Code:
Enter the input string:
well
j is 1
j is 2
j is 3
j is 4
The encrypted value is
120 121 122 123
Thanks
Which assignment you want to move outside of for loop?
def Encrypt(input):
res=''
j=1
for i in input:
k = len(input) + 1
while j < k:
print("j is ",j)
val = ord(i) + j
res = res + ' ' + str(val)
j = j + 1
break
return res
input=str(input("Enter the input string:\n"))
result=Encrypt(input)
print("The encrypted value is\n",result)
Nope, that's not your original program. Go through the program you posted in your first post carefully and ensure that it is identical to the one above, except for the assignment statement i.e. j = 1.
(Hint: check the indentation of each line.)
Quote:
...
Which assignment you want to move outside of for loop?
Code:
j=1
is already moved before for loop.
Yes I know. That was mentioned in my first post itself.
I have the following code:
#!/usr/bin/env python
mylist =
def printWithoutNewlines():
for objects in mylist:
#print(objects)
objects = objects.replace('hello', "hi")
print objects
When executed, it gives the following output:
## ./loop.py
hi... (3 Replies)
This site is the first to get this snippet.
It will capture an audio recording of any time length within the limits of OSX's QuickTime Player's capablility...
A shell script derivative of this will be used as a further capture for CygWin's AudioScope.sh.
Thoroughly read ALL the comments in... (0 Replies)
Hi all,
I'm looking for secure file encryption tools that use MAC address as encryption key. FYI, I'm using Red Hat Enterprise Linux OS.
For example: when A wants to send file to B
A will encrypt the file with B's computer MAC/IP address as an encryption key
This file can only be decrypted... (2 Replies)
I have the following problem, which I need done in Perl/ or Python using Unix/linux filters...
1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values... (1 Reply)
I have the following problem, which I need done in Perl/ or Python using Unix/linux filters...
1. You have a very large file, named 'ColCheckMe', tab-delmited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the... (1 Reply)
Building software in most languages is a pain. Remember ant build.xml, maven2 pom files, and multi-level makefiles?
Python has a simple solution for building modules, applications, and extensions called distutils. Disutils comes as part of the Python distribution so there are no other packages... (0 Replies)