其实,也就几句话!

def03.py

3.检测是否安装成功并输出Hello World

ok,这就是全部代码了,请容在下粗略的介绍下实现步骤:

 

图片 1安装完成

打开C盘,直接搜索!

#
对象在不描述之前什么都不是。
#
对象就是需要描述它的动作和特征,才能去定义它。比如:人,长什么样,能做什么;灯泡,是什么样,能做什么。

 

找到的,直接引用到项目里就行了哈!

# 那么一个函数,
#
就是给定不同属性,设置属性到它内部,
#
并且它内部的函数使用了这些属性,完成了新的动作,
#
通过返回方法至一个字典当中,让外部调用这个方法(属性和方法都需要让外部去访问,在字典类型当中来讲,是平等的),
#
即完成了所谓的【面向对象】

1.下载python安装版Windows x86-64 executable
installer

好吧,教你一招

类就像模板,定义后就是一个对象了。

 

  using
System.Speech.Synthesis;  //语音类库

你写的程序是不是面向对象的,和你用的语言是不是面向对象的无关系!面向对象设计,只不过是函数/过程式编程的演进。关键在于面向对象的设计思路。

图片 2

好了,其他的代码就要看小主的内力了,在下就不多说了!

 6 
 7 def dog(name,gender,type):
 8     def jiao(dog):
 9         print('一条狗[%s],汪汪'%dog['name'])
10 
11     def yaoren(dog):
12         print('一条狗[%s]正在咬人'%dog['type'])
13 
14     dog1 = {
15         'name': name,
16         'gender': gender,
17         'type': type,
18         'jiao':jiao,#内部函数
19         'yaoren':yaoren#内部函数
20     }
21     return dog1#因为作用域的问题,所以一定要用内部的return 返回jiao,yaoren的函数,才能被外部调用
22 
23 d1 = dog('张明','母','腊肠')

24 d1['jiao'](d1)#引入返回的那个数组d1 ,

图片 3

2.其次,别忘了引用下这两个命名空间:

 6 
 7 def dog():
 8     def jiao(dog):
 9         print('一条狗[%s],汪汪'%dog['name'])
10 
11     def yaoren(dog):
12         print('一条狗[%s]正在咬人'%dog['type'])
13 
14     dog1 = {
15         'name': '元昊',
16         'gender': '母',
17         'type': '藏獒',
18         'jiao':jiao,
19         'yaoren':yaoren
20     }
21     return dog1
22 
23 d1 = dog()
24 d1['jiao'](d1)

2.开始安装

技术讨论群:225443677
有意者欢迎骚扰,谢谢!

 

图片 4

“好的,老大!”

 def02.py

 图片 5

SpeechSynthesizer spvoice = new SpeechSynthesizer();  //语音类
spvoice.Rate = 1;            //使用 spvoice 设置朗读频率 [范围 -10 ~ 10] 
spvoice.Volume = 80;         //使用 spvoice 设置朗读音量 [范围 0 ~ 100] 
spvoice.SpeakAsync("大家好,我是博主小白!");   //开始读

def01.py

图片 6

using System;
using System.Speech.Synthesis;
using System.Collections.Generic;

namespace ReadTxt
{
    class Program
    {

        static string num1 = "", firchar = "", lastchar = "", tempRe = "";

        static void Main(string[] args)
        {

            Console.Title = "语音计算器";
            bool jump = true;
            do
            {

                ConsoleKeyInfo info = Console.ReadKey();
                switch (info.Key)
                {
                    case ConsoleKey.Escape: Environment.Exit(0); jump = false; break;
                    case ConsoleKey.NumPad0:    GetKeyRead("0");     break;
                    case ConsoleKey.NumPad1:    GetKeyRead("1");     break;
                    case ConsoleKey.NumPad2:    GetKeyRead("2");     break;
                    case ConsoleKey.NumPad3:    GetKeyRead("3");     break;
                    case ConsoleKey.NumPad4:    GetKeyRead("4");     break;
                    case ConsoleKey.NumPad5:    GetKeyRead("5");     break;
                    case ConsoleKey.NumPad6:    GetKeyRead("6");     break;
                    case ConsoleKey.NumPad7:    GetKeyRead("7");     break;
                    case ConsoleKey.NumPad8:    GetKeyRead("8");     break;
                    case ConsoleKey.NumPad9:    GetKeyRead("9");     break;
                    case ConsoleKey.Add:        GetKeyRead("加");    break;
                    case ConsoleKey.Subtract:   GetKeyRead("减");    break;
                    case ConsoleKey.Multiply:   GetKeyRead("乘");    break;
                    case ConsoleKey.Divide:     GetKeyRead("除");    break;
                    case ConsoleKey.Enter:
                        if (!string.IsNullOrEmpty(num1) && GetSignIsTrue(num1))
                        {
                            SetValue(num1);
                            num1 = "";
                        }
                        else
                        {
                            num1 = "";
                            if (!string.IsNullOrEmpty(num1))
                            {
                                Console.Beep();
                                Console.WriteLine("Error.");
                            }
                        }
                        break;
                    default:
                        break;
                }
            } while (jump);
            Console.Read();
        }

        //判断用户输入的内容是否合法
        static void GetKeyRead(string str)
        {
            SpeechSynthesizer spvoice = new SpeechSynthesizer();
            spvoice.Rate = 1;
            spvoice.Volume = 100;

            if (!string.IsNullOrEmpty(num1))
            {
                firchar = num1.Substring(0, 1);
                lastchar = num1.Substring(num1.Length - 1, 1);
            }

            switch (str)
            {
                case "加":
                    if (firchar != "加" && lastchar != "加")
                    {
                        if (lastchar != "减" && lastchar != "乘" && lastchar != "除")
                        {
                            num1 += str;
                        }
                        else
                        {
                            num1 = num1.Remove(num1.Length - 1);
                            num1 += str;
                        }
                    }

                    break;
                case "减":
                    if (firchar != "减" && lastchar != "减")
                    {
                        if (lastchar != "加" && lastchar != "乘" && lastchar != "除")
                        {
                            num1 += str;
                        }
                        else 
                        {
                            num1 = num1.Remove(num1.Length - 1);
                            num1 += str;
                        }
                    }

                    break;
                case "乘":
                    if (firchar != "乘" && lastchar != "乘")
                    {
                        if (lastchar != "加" && lastchar != "减" && lastchar != "除")
                        {
                            num1 += str;
                        }
                        else
                        {
                            num1 = num1.Remove(num1.Length - 1);
                            num1 += str;
                        }
                    }
                    break;
                case "除":
                    if (firchar != "除" && lastchar != "除")
                    {
                        if (lastchar != "加" && lastchar != "减" && lastchar != "乘")
                        {
                            num1 += str;
                        }
                        else
                        {
                            num1 = num1.Remove(num1.Length - 1);
                            num1 += str;
                        }
                    }
                    break;
                default:
                    num1 += str;
                    break;
            }
            spvoice.SpeakAsync(str);
            Console.Clear();
            Console.Write(tempRe + num1.Replace('加', '+').Replace('减', '-').Replace('乘', '*').Replace('除', '/').Replace("等于", "="));
        }

        static bool GetSignIsTrue(string num1) 
        {
            if (!string.IsNullOrEmpty(num1))
            {
                firchar = num1.Substring(0, 1);
                lastchar = num1.Substring(num1.Length - 1, 1);
            }

            return firchar != "加" && lastchar != "加" && firchar != "减" && lastchar != "减" && firchar != "乘" && lastchar != "乘" && firchar != "除" && lastchar != "除";
        }

        //计算
        static void SetValue(string num1)
        {
            List<double> array = new List<double>();
            List<string> sign = new List<string>();
            num1 = num1.Replace('加', '+').Replace('减', '-').Replace('乘', '*').Replace('除', '/');
            string tempCap = "";
            char[] MyChar = num1.ToCharArray();
            for (int i = 0; i < MyChar.Length; i++)
            {
                if (MyChar[i].ToString() == "+" || MyChar[i].ToString() == "-" || MyChar[i].ToString() == "*" || MyChar[i].ToString() == "/")
                {
                    array.Add(Convert.ToDouble(tempCap));
                    tempCap = "";
                    sign.Add(MyChar[i].ToString());
                }
                else
                {
                    if (i == MyChar.Length - 1)
                    {
                        tempCap += MyChar[i].ToString();
                        array.Add(Convert.ToDouble(tempCap));
                    }
                    else
                    {
                        tempCap += MyChar[i].ToString();
                    }
                }
            }

            double resultTemp = 0;
            for (int i = 0; i < sign.ToArray().Length; i++)
            {
                if (sign[i] == "*")
                {
                    resultTemp = array[i] * array[i + 1];
                    array[i] = resultTemp;
                    array.Remove(array[i + 1]);
                    sign.Remove(sign[i]);
                    resultTemp = 0;
                    i--;
                }
                else if (sign[i] == "/")
                {
                    resultTemp = array[i] / array[i + 1];
                    array[i] = resultTemp;
                    array.Remove(array[i + 1]);
                    sign.Remove(sign[i]);
                    resultTemp = 0;
                    i--;
                }
            }

            for (int i = 0; i < sign.ToArray().Length; i++)
            {
                if (sign[i] == "+")
                {
                    resultTemp = array[i] + array[i + 1];
                    array[i] = resultTemp;
                    array.Remove(array[i + 1]);
                    sign.Remove(sign[i]);
                    resultTemp = 0;
                    i--;
                }
                else if (sign[i] == "-")
                {
                    resultTemp = array[i] - array[i + 1];
                    array[i] = resultTemp;
                    array.Remove(array[i + 1]);
                    sign.Remove(sign[i]);
                    resultTemp = 0;
                    i--;
                }
            }

            double answ = array[0];
            array.Clear();
            sign.Clear();
            tempRe += num1.Replace('加', '+').Replace('减', '-').Replace('乘', '*').Replace('除', '/') + "= " + answ + "\n";
            GetKeyRead("等于" + answ);
        }
    }
}
 6 
 7 def dog(name,gender,type):
 8     def jiao(dog):
 9         print('一条狗[%s],汪汪'%dog['name'])
10 
11     def yaoren(dog):
12         print('一条狗[%s]正在咬人'%dog['type'])
13 
14     def init(name,gender,type):
15         dog1 = {
16             'name': name,
17             'gender': gender,
18             'type': type,
19             'jiao':jiao,#内部函数
20             'yaoren':yaoren#内部函数
21         }
22         return dog1
23 
24     return init(name,gender,type)
25 
26 d1 = dog('张明','母','腊肠')

26 print(d1['name'],d1['gender'])

27 d1['jiao'](d1)#引入返回的那个数组d1 ,

什么?这个类库叫啥?

def04.py

发表评论

电子邮件地址不会被公开。 必填项已用*标注