2016-04-14 11 views
-4

Ich habe den Code unten:Mein Python GUI sagte immer wieder ein int ein Tupel

# Hello World program in Python 

def timesummer(str1): 
    str2="." 
    location=str1.find(str2,) 
    location=location-1 
    location1=int(location) 
    strmin=str1[0,location] 
    float1=float(strmin) 
    minutes=int(float1) 
    location=location+1 
    strsec=str1[location,len(str1)-1] 
    float2=float(strsec) 
    seconds=int(seconds) 
    finalanswer=seconds+(minutes*60) 
    return finalanswer 

print timesummer("1.10") 

Und wenn ich es laufen, sagt es, dass bei strmin str1 = [0, location] ist nicht gültig, weil ich verwende einen Tupelwert? Wie repariere ich den Code? Verwende ich einen Tupelwert?

+0

leider erste Mal mit statck Überlauf, nicht sicher, wie – Panda

+0

# schreiben Hallo Weltprogramm in Python def mal summer (str1): str2 = "." location = str1.find (STR2,) location = location1 location1 = int (Ort) strmin str1 = [0, location] float1 = float (strmin) Minuten = int (float1) location = Ort + 1 strsec = str1 [Lage, len (sTR1) -1] float2 = float (strsec) Sekunden = int (Sekunden) finalanswer = Sekunden + (min * 60) return finalanswer Druck timesummer ("1.10") – Panda

+1

Was erwarten Sie, wenn Sie 'strmin = str1 [0, lo Kation] '? Suchen Sie nach ':', dem Slice Operator? –

Antwort

1

Slicing verwendet einen Doppelpunkt, kein Komma:

str1[0:location] 

(Sie können aber auch das 0. auslassen)