Please see my below code, I'm trying to use user input to select specific rows within a dataframe. I'm not sure if it's my loop that is causing the issues? As when I run the code outside of the function the code seems to work. Any help would be great.
Thanks
def option3():
print("---------------------------")
print("please select from the following options")
print(Ndata[" workclass"].unique())
print("---------------------------")
loop3 = True
while loop3:
print("---------------------------")
Op1 = input('Please enter first working class: ')
Op2 = input('Please enter second working class: ')
print("Options selected ", Op1, "&", Op2)
print("---------------------------")
if Op1 and Op2 in Ndata[" workclass"]:
loop3 = False
sub = Ndata.loc[Ndata[" workclass"].isin([Op1, Op2])]
print("---------------------------")
print("PLease select frome the following")
print("[1] Most educated countries ")
print("[2] Marital status ")
print("---------------------------")
Op3 = int(input("PLease enter 1 or 2 : "))
loop4 = True
while loop4:
if Op3 == 1 or 2 :
loop4 = False
else:
print('PLease select 1 or 2')
else:
print("Please check", Op1, "&", Op2, " are in the working class")
print(Ndata[" workclass"].unique())
Related
def yetkiligoruntule(self):
self.ui.tableWidgetYetkilileriGoster.setRowCount(0)
query = "SELECT yetkili_id, yetkili_ad, yetkili_soyad, yetkili_num, yetkili_mail, yetkili_poz FROM yetkili"
result = cur.execute(query,).fetchall()
for row in result:
rowNumber = self.ui.tableWidgetYetkilileriGoster.rowCount()
self.ui.tableWidgetYetkilileriGoster.insertRow(rowNumber)
for columnNumber, data in enumerate(row):
self.ui.tableWidgetYetkilileriGoster.setItem(rowNumber, columnNumber, QTableWidgetItem(str(data)))
def yetkiliAra(self):
value = self.ui.lineEditYetkiliAra.text()
if value == "":
QMessageBox.warning(self,"Uyari","Lutfen yetkili adi giriniz!")
self.ui.lineEditYetkiliAra.setText("")
else:
query = "SELECT yetkili_id, yetkili_ad, yetkili_soyad, yetkili_num, yetkili_mail, yetkili_poz FROM yetkili WHERE yetkili_ad LİKE? or yetkili_soyad LİKE?"
result = cur.execute(query,('%' + value + '%','%' + value + '%'))
if result == []:
QMessageBox.warning(self,"Uyari","Kullanici Bulunamadi!")
self.ui.lineEditYetkiliAra.setText("")
return
else:
**self.ui.tableWidgetYetkilileriGoster.setRowCount(0)**
for row in result:
rowNumber = self.ui.tableWidgetYetkilileriGoster.rowCount()
self.ui.tableWidgetYetkilileriGoster.insertRow(rowNumber)
for columnNumber, data in enumerate(row):
self.ui.tableWidgetYetkilileriGoster.setItem(rowNumber, columnNumber, QTableWidgetItem(str(data)))
I think this line (which is bold) is the exact problem. Bu don't know how to solve it. Is there someone for help?
Just try ask here. I try to 'setRowCount()' like this without 0 but it doesn't work.
I have a question I wrote this script to format an arabic text to a certain format. But I found a problem then when I type a longer sentence it adds more dots then there are letters. I will paste the code here and explain what the problem is.
import itertools
while True:
input_cloze_deletion = input("\nEnter: text pr 'exit'\n> ")
input_exit_check = input_cloze_deletion.strip().lower()
if input_exit_check == "exit":
break
# copy paste
interpunction_list = ["الله", ",", ".", ":", "?", "!", "'"]
# copy paste
interpunction_list = [ ",", ".", ":", "?", "!", "'", "-", "(", ")", "/", "الله", "اللّٰـه"]
text_replace_0 = input_cloze_deletion.replace(",", " ,")
text_replace_1 = text_replace_0.replace(".", " .")
text_replace_2 = text_replace_1.replace(":", " :")
text_replace_3 = text_replace_2.replace(";", " ;")
text_replace_4 = text_replace_3.replace("?", " ?")
text_replace_5 = text_replace_4.replace("!", " !")
text_replace_6 = text_replace_5.replace("'", " ' ")
text_replace_7 = text_replace_6.replace("-", " - ")
text_replace_8 = text_replace_7.replace("(", " ( ")
text_replace_9 = text_replace_8.replace(")", " ) ")
text_replace_10 = text_replace_9.replace("/", " / ")
text_replace_11 = text_replace_10.replace("الله", "اللّٰـه")
text_split_list = text_replace_11.split()
count_number = []
letter_count_list = []
index_list = itertools.cycle(range(1, 4))
for letter_count in text_split_list:
if letter_count in interpunction_list:
letter_count_list.append(letter_count)
elif "ـ" in letter_count:
letter_count = len(letter_count) - 1
count_number.append(letter_count)
print(letter_count)
else:
letter_count = len(letter_count)
count_number.append(letter_count)
print(letter_count)
for count in count_number:
letter_count_list.append(letter_count * ".")
zip_list = zip(text_split_list, letter_count_list)
zip_list_result = list(zip_list)
for word, count in zip_list_result:
if ((len(word)) == 2 or word == "a" or word == "و") and not word in interpunction_list :
print(f" {{{{c{(next(index_list))}::{word}::{count}}}}}", end="")
elif word and count in interpunction_list:
print(word, end = "")
else:
print(f" {{{{c{(next(index_list))}::{word}::{count}}}}}", end="")
when I type كتب عليـ ـنا و علـ ـي
the return is {{c1::كتب::...}} {{c2::عليـ::...}} {{c3::ـنا::...}} {{c1::و::..}} {{c2::علـ::..}} {{c3::ـي::..}}
but it should be
{{c1::كتب::...}} {{c2::عليـ::...}} {{c3::ـنا::..}} {{c1::و::.}} {{c2::علـ::..}} {{c3::ـي::.}}
I add a print function the print the len() results and the result is correct but it add an extra dot in some case.
But when I type just a single "و" it does a correct len() function but when I input a whole sentence it add an extra dot and I don't know why.
please help
def main():
randOperation = Randomchoice(operation)
while True:
try:
randOperation()
randOperation = choice(operation)
userAns=int(input("Answer: "))
if userAns == answers:
print("Correct!" + "\n")
score = score + 1
NumOfTries =NumOfTries + 1
else:
print("Incorrect!" + "\n")
NumOfTries = NumOfTries + 1 #here is where the issue is
I am trying to convert a number to a word from a RDLC report:
Public Shared Function changeToWords(ByVal numb As [String]) As [String]
Dim val As [String] = ""
Dim wholeNo As [String] = numb
Dim points As [String] = ""
Dim andStr As [String] = ""
Dim pointStr As [String] = ""
Dim endStr As [String] = ""
Try
Dim decimalPlace As Integer = numb.IndexOf(".")
If decimalPlace > 0 Then
wholeNo = numb.Substring(0, decimalPlace)
points = numb.Substring(decimalPlace + 1)
If Convert.ToInt32(points) > 0 Then
andStr = "point"
' just to separate whole numbers from points
pointStr = translateCents(points)
End If
End If
val = [String].Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr)
Catch
End Try
Return val
End Function
Private Shared Function translateWholeNumber(ByVal number As [String]) As [String]
Dim word As String = ""
Try
Dim beginsZero As Boolean = False
'tests for 0XX
Dim isDone As Boolean = False
'test if already translated
Dim dblAmt As Double = (Convert.ToDouble(number))
'if ((dblAmt > 0) && number.StartsWith("0"))
If dblAmt > 0 Then
'test for zero or digit zero in a nuemric
beginsZero = number.StartsWith("0")
Dim numDigits As Integer = number.Length
Dim pos As Integer = 0
'store digit grouping
Dim place As [String] = ""
'digit grouping name:hundres,thousand,etc...
Select Case numDigits
Case 1
'ones' range
word = ones(number)
isDone = True
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 2
'tens' range
word = tens(number)
isDone = True
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 3
'hundreds' range
pos = (numDigits Mod 3) + 1
place = " Hundred "
Exit Select
' TODO: might not be correct. Was : Exit Select
'thousands' range
Case 4, 5, 6
pos = (numDigits Mod 4) + 1
place = " Thousand "
Exit Select
' TODO: might not be correct. Was : Exit Select
'millions' range
Case 7, 8, 9
pos = (numDigits Mod 7) + 1
place = " Million "
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 10
'Billions's range
pos = (numDigits Mod 10) + 1
place = " Billion "
Exit Select
Case Else
' TODO: might not be correct. Was : Exit Select
'add extra case options for anything above Billion...
isDone = True
Exit Select
' TODO: might not be correct. Was : Exit Select
End Select
If Not isDone Then
'if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
'check for trailing zeros
If beginsZero Then
word = " and " & word.Trim()
End If
End If
'ignore digit grouping names
If word.Trim().Equals(place.Trim()) Then
word = ""
End If
End If
Catch
End Try
Return word.Trim()
End Function
Private Shared Function tens(ByVal digit As [String]) As [String]
Dim digt As Integer = Convert.ToInt32(digit)
Dim name As [String] = Nothing
Select Case digt
Case 10
name = "Ten"
Exit Select
' TODO: might not be correct. Was : Exit Select \
Case 11
name = "Eleven"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 12
name = "Twelve"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 13
name = "Thirteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 14
name = "Fourteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 15
name = "Fifteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 16
name = "Sixteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 17
name = "Seventeen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 18
name = "Eighteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 19
name = "Nineteen"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 20
name = "Twenty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 30
name = "Thirty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 40
name = "Fourty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 50
name = "Fifty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 60
name = "Sixty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 70
name = "Seventy"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 80
name = "Eighty"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 90
name = "Ninety"
Exit Select
Case Else
' TODO: might not be correct. Was : Exit Select
If digt > 0 Then
name = (Convert.ToString(tens(digit.Substring(0, 1) & "0")) & " ") & Convert.ToString(ones(digit.Substring(1)))
End If
Exit Select
' TODO: might not be correct. Was : Exit Select
End Select
Return name
End Function
Private Shared Function ones(ByVal digit As [String]) As [String]
Dim digt As Integer = Convert.ToInt32(digit)
Dim name As [String] = ""
Select Case digt
Case 1
name = "One"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 2
name = "Two"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 3
name = "Three"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 4
name = "Four"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 5
name = "Five"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 6
name = "Six"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 7
name = "Seven"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 8
name = "Eight"
Exit Select
' TODO: might not be correct. Was : Exit Select
Case 9
name = "Nine"
Exit Select
' TODO: might not be correct. Was : Exit Select
End Select
Return name
End Function
Private Shared Function translateCents(ByVal cents As [String]) As [String]
Dim cts As [String] = ""
Dim digit As [String] = ""
Dim engOne As [String] = ""
For i As Integer = 0 To cents.Length - 1
digit = cents(i).ToString()
If digit.Equals("0") Then
engOne = "Zero"
Else
engOne = ones(digit)
End If
cts += " " & engOne
Next
Return cts
End Function
I am getting the wrong output from the conversion.
For 52001 the given output is Fifty Two Thousand and Hundred One.
However, it should be Fifty Two Thousand and One.
You'll need to add a conditional statement to modify your string concatenation behavior when the beginning of your substring is a zero.
'if transalation is not done, continue...(Recursion comes in now!!)
If (number.Substring(0, 1) = "0") Then
word = translateWholeNumber(number.Substring(pos))
Else
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
End If
Edit: Doing this breaks output if the original string sent to changeToWords begins with any zeros. To rectify that condition, you can trim leading zeros, before the string is processed:
Dim wholeNo As [String] = numb.TrimStart("0"c)
Just change this line:
If Not isDone Then
'if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos))
'check for trailing zeros
If beginsZero Then
word = translateWholeNumber(number.Substring(0, pos))+ " and " + translateWholeNumber(number.Substring(pos))
End If
End If
I'm trying to write a program that collects information from the user, then outputs to a text file. The program collects input correctly, as the print statement I inserted tells me, but the break statement doesn't break the loop when the specified value is input, and the output file is never updated. Any suggestions you could give would really help. Thanks!
# 1. Define Greeting:
def greeting():
print("Welcome, user! Please enter the address data, or type 'quit'.")
# 2. Input
def inputData():
name = input("Enter the name: ")
address = input("Enter the address: ")
city = input("Enter the city: ")
state = input("Enter the state: ")
zipCode = input("Enter the zip: ")
phone = input("Enter the phone number: ")
addressData = str(name + ", " + address + ", " +
city + ", " + state + ", "+ zipCode +
", " + phone)
print(addressData)
return(name)
# 3. Write data to text file
def dataWrite():
f.write(addressData + "\n")
# 4. Display the goodbye message:
def goodbye():
print("Have a nice day!")
# 5. Define Main function:
def main():
greeting()
while name != "quit":
inputData()
if name == "quit":
break
else:
dataWrite()
f.close()
goodbye()
main()
def main():
greeting()
while name != "quit":
name = inputData()
if name == "quit":
break
else:
dataWrite()
f.close()
goodbye()
You are not getting the return value of inputData().